我正在尝试运行一个python脚本(不是我的),它应该连接到LAN上的IP地址(192.168.1.3)。
File "control/insert_to_container.py", line 36, in <module>
res=read_info.open_file()
File "/control/read_info.py", line 21, in open_file
r = requests.get('http://'+line.rstrip('\t')+':491155')
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.3', port=491155): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8fd9e9b250>: Failed to establish a new connection: [Errno 111] Connection refused',))
我在配置文件中指定了IP地址。有人会知道错误%09
中的HTTPConnectionPool(host=192.168.1.3%09
是什么。我想知道这是否是错误的来源。
答案 0 :(得分:0)
您的变量“line”包含一个标签,然后由Requests库将其变为“%09”。
要解决此问题,您必须首先确保您的“line”变量不包含任何无关的字符。实现此目标的最直接方法是使用.rstrip()
示例:
r = requests.get('http://'+line.rstrip('\t')+':49155')