问题:Python请求-无连接适配器

我正在使用Requests:HTTP for Humans库,但出现了这个奇怪的错误,我不知道这是什么意思。

No connection adapters were found for '192.168.1.61:8080/api/call'

有人有主意吗?

I’m using the Requests: HTTP for Humans library and I got this weird error and I don’t know what is mean.

No connection adapters were found for '192.168.1.61:8080/api/call'

Anybody has an idea?


回答 0

您需要包括协议方案:

'http://192.168.1.61:8080/api/call'

没有这个http://部分,requests就不知道如何连接到远程服务器。

请注意,协议方案必须全部为小写。如果您的URL以HTTP://例如开头,则也找不到http://连接适配器。

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.

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.


回答 1

另一个原因,也许您的URL包含一些隐藏的字符,例如’\ n’。

如果您按如下方式定义网址,则会引发此异常:

url = '''
http://google.com
'''

因为字符串中有’\ n’隐藏。该网址实际上变为:

\nhttp://google.com\n

One more reason, maybe your url include some hiden characters, such as ‘\n’.

If you define your url like below, this exception will raise:

url = '''
http://google.com
'''

because there are ‘\n’ hide in the string. The url in fact become:

\nhttp://google.com\n

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。