[英]Python Requests - No connection adapters
I'm using the Requests: HTTP for Humans library and I got this weird error and I don't know what is mean.我正在使用Requests: HTTP for Humans库,我收到了这个奇怪的错误,我不知道这是什么意思。
No connection adapters were found for '192.168.1.61:8080/api/call'
Anybody has an idea?有人有想法吗?
You need to include the protocol scheme: 您需要包括协议方案:
'http://192.168.1.61:8080/api/call'
Without the http://
part, requests
has no idea how to connect to the remote server. 没有
http://
部分, requests
不知道如何连接到远程服务器。
Note that the protocol scheme must be all lowercase; 请注意,协议方案必须全部为小写。 if your URL starts with
HTTP://
for example, it won't find the http://
connection adapter either. 例如,如果您的URL以
HTTP://
开头,则也不会找到http://
连接适配器。
One more reason, maybe your url include some hiden characters, such as '\\n'. 另一个原因,也许您的URL包含一些隐藏的字符,例如'\\ n'。
If you define your url like below, this exception will raise: 如果您按如下方式定义网址,则会引发此异常:
url = '''
http://google.com
'''
because there are '\\n' hide in the string. 因为字符串中有'\\ n'隐藏。 The url in fact become:
该网址实际上变为:
\nhttp://google.com\n
In my case, I received this error when I refactored a url, leaving an erroneous comma thus converting my url from a string into a tuple.就我而言,我在重构 url 时收到此错误,留下错误的逗号,从而将我的 url 从字符串转换为元组。
My exact error message:我的确切错误信息:
741 # Nothing matches :-/
--> 742 raise InvalidSchema("No connection adapters were found for {!r}".format(url))
743
744 def close(self):
InvalidSchema: No connection adapters were found for "('https://api.foo.com/data',)"
Here's how that error came to be born:以下是该错误的产生方式:
# Original code:
response = requests.get("api.%s.com/data" % "foo", headers=headers)
# --------------
# Modified code (with bug!)
api_name = "foo"
url = f"api.{api_name}.com/data", # !!! Extra comma doesn't belong here!
response = requests.get(url, headers=headers)
# --------------
# Solution: Remove erroneous comma!
api_name = "foo"
url = f"api.{api_name}.com/data" # No extra comma!
response = requests.get(url, headers=headers)
Fix connection adapter matching to be most-specific first,Miscellaneous small Python 3 text encoding bugs.,.netrc no longer overrides explicit auth.,Mountable Connection Adapters修复连接适配器匹配首先是最具体的,杂项小 Python 3 文本编码错误。,.netrc 不再覆盖显式身份验证。,可安装的连接适配器
To install Requests, simply:要安装请求,只需:
$ pip install requests $ pip 安装请求
As stated in a comment by christian-long正如christian-long在评论中所说
Your url may accidentally be a tuple because of a trailing comma由于尾随逗号,您的 url 可能意外成为元组
url = self.base_url % endpoint,
Make sure it is a string确保它是一个字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.