Python 请求 - 没有连接适配器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15115328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:23:05  来源:igfitidea点击:

Python Requests - No connection adapters

pythonpython-2.7python-requests

提问by Azd325

I'm using the Requests: HTTP for Humanslibrary 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?

有人有想法吗?

采纳答案by Martijn Pieters

You need to include the protocol scheme:

您需要包括协议方案:

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

Without the http://part, requestshas 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://连接适配器。

回答by Kingname

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. The url in fact become:

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

\nhttp://google.com\n