Python请求 - 没有连接适配器

Azd*_*325 178 python python-2.7 python-requests

我正在使用Requests:HTTP for Humans library,我得到了这个奇怪的错误,我不知道是什么意思.

No connection adapters were found for '192.168.1.61:8080/api/call'
Run Code Online (Sandbox Code Playgroud)

有人有想法吗?

Mar*_*ers 328

您需要包含协议方案:

'http://192.168.1.61:8080/api/call'
Run Code Online (Sandbox Code Playgroud)

没有该http://部分,requests不知道如何连接到远程服务器.


Kin*_*ame 22

还有一个原因,也许你的网址包含一些隐藏字符,例如'\n'.

如果您定义如下所示的网址,则此异常将引发:

url = '''
http://google.com
'''
Run Code Online (Sandbox Code Playgroud)

因为字符串中有'\n'隐藏.网址实际上变成:

\nhttp://google.com\n
Run Code Online (Sandbox Code Playgroud)

  • 或者如果你的url因为尾随逗号`url = self.base_url%endpoint而意外地成为元组, (7认同)

Yaa*_*ler 8

就我而言,当我重构 url 时收到此错误,留下错误的逗号,从而将我的 url 从字符串转换为元组。

我的确切错误消息:

    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',)"
Run Code Online (Sandbox Code Playgroud)

这个错误是这样产生的:

    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',)"
Run Code Online (Sandbox Code Playgroud)