"D:\Program Files (x86)\Python38\python.exe" D:/PycharmProjects/pythonProject/driver_api_auto/excel_load.py
Traceback (most recent call last):
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connection.py", line 158, in _new_conn
conn = connection.create_connection(
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\util\connection.py", line 57, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "D:\Program Files (x86)\Python38\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
conn.connect()
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connection.py", line 301, in connect
conn = self._new_conn()
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connection.py", line 167, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x047DFF40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Program Files (x86)\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "D:\Program Files (x86)\Python38\lib\site-packages\urllib3\util\retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='test-gw-driver.01zhuanche.com%0a', port=443): Max retries exceeded with url: /gw-driver/zhuanche-driver/driver/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x047DFF40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/PycharmProjects/pythonProject/driver_api_auto/excel_load.py", line 54, in <module>
resp = send(url=url, method=method, headers=headers, **params)
File "D:\PycharmProjects\pythonProject\driver_api_auto\requests_client.py", line 19, in send
resp = session.request(url=url, method=method, **kwargs, verify=False, timeout=2)
File "D:\Program Files (x86)\Python38\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "D:\Program Files (x86)\Python38\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "D:\Program Files (x86)\Python38\lib\site-packages\requests\adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='test-gw-driver.01zhuanche.com%0a', port=443): Max retries exceeded with url: /gw-driver/zhuanche-driver/driver/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x047DFF40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
Process finished with exit code 1
首先
resp = session.request(url=url, method=method, **kwargs, verify=False, timeout=2)
# 你这个写法是不是有问题
# "默认传参" 应该放在 "**kwargs" 前面吧
resp = session.request(url=url, method=method,verify=False, timeout=2, **kwargs)
其次,打印显示底层依赖(site-packages)报错前,requests_client.py 是最后报错的位置,你自己 debug 一下
requests_client.py 文件
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
session = requests.session()
def send(url, method, **kwargs):
resp = session.request(url=url, method=method, verify=False, timeout=2, **kwargs)
# resp = session.request(url=url, method=method, **kwargs)
return resp
@行者逍遥: ???
@〆灬丶: requests_client.py 这个文件是封装,用来调用的
这是方法
def send(url, method, **kwargs):
resp = session.request(url=url, method=method, verify=False, timeout=2, **kwargs)
return resp
运行 print(resp.text) 后报错
File "D:\Program Files (x86)\Python38\lib\site-packages\requests\adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='test-gw-driver.01zhuanche.com%0a', port=443): Max retries exceeded with url: /gw-driver/zhuanche-driver/driver/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x047DFF40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
Process finished with exit code 1
这一步debug resp = send(url=url, method=method, headers=headers, **params)debug结果:
@行者逍遥:
有两个疑问:
1.为啥不直接用 requests 去请求(另外,你可以先用 postman 去测试接口然后生成 Python 请求代码)
2. 最后一张截图,url 里为啥还有换行符
PS:同样的截图就不要重复发了,你发的累,我看着也累
@〆灬丶: OK
我这个是写的Python 接口自动化的框架,postman感觉不适合 ;(Python 写的都是封装后,其他去调用封装;postman不知道怎么模拟这种场景。postman只用过单接口运行和关联接口操作。
文件
)
@行者逍遥: postman 是用来测试接口通不通的,起码能把url 带换行符的问题测出来
@〆灬丶: 接口是通的,已经运行过了
@〆灬丶:
@行者逍遥: 意思是问题解决了?
@〆灬丶: 我的问题是?
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='test-gw-driver.01zhuanche.com%0a', port=443): Max retries exceeded with url: /gw-driver/zhuanche-driver/driver/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0476FF40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
上面那个是接口的类单独运行的,接口没有问题。 运行的类调用其他类的时候报的错
@行者逍遥:
https://test-gw-driver.01zhuamche.com\n/gw-driver/zhuanche-driver/driver/login
Failed to establish a new connection: [Errno 11001] getaddrinfo failed
这个报错,接口是怎么通的?前面都说链接失败了,这也能通?@行者逍遥: 另外,你反复强调接口没问题,我问的就是你贴的报错里面的 API HTTPSConnectionPool(host='test-gw-driver.01zhuanche.com%0a', port=443): Max retries exceeded with url: /gw-driver/zhuanche-driver/driver/login
@〆灬丶: 报错文件里没有api,API在其他的类里
@〆灬丶: 单独运行接口文件没有问题。URL的换行符是调用api类的时候拼接生成的,不是直接请求url.
@〆灬丶:现在最大的问题是这个,其他的先等这个解决了再看。这个是重点
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='test-gw-driver.01zhuanche.com%0a', port=443): Max retries exceeded with url: /gw-driver/zhuanche-driver/driver/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0476FF40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))