python - Python请求获取未找到连接适配器
问题描述
我可以执行 urlprase 并将其传递给如下请求吗?我传递的网址是https://server1:8089
url = urlparse(args.URL)
def rest():
url = {
'scheme': 'https',
'host': url.netloc,
'port': url.port if url.port else 8089,
'path': '/services/search/distributed/peers',
'http_auth': (user + ":" + password),
'use_ssl': True,
'verify_certs': True,
'ca_certs': certifi.where()
}
headers = {"Content-Type": "application/json"}
payload = {
"name": "test",
"remoteUsername": user,
"remotePassword": password
}
try:
re = requests.post(url, data=payload, headers=headers)
print(re.text)
except requests.exceptions.RequestException as e:
print(e)
exit(1)
错误
No connection adapters were found for '{'scheme': 'https', 'host': 'server1', 'port': 8089, 'path': '/services/search/distributed/peers', 'http_auth': 'user:pass', 'use_ssl': True, 'verify_certs': True, 'ca_certs': 'C:\\Users\\User1\\Local\\Programs\\Python\\Python36\\lib\\site-packages\\certifi\\cacert.pem'}'
我不确定这是将 urlparse 传递给请求的正确方法,我能够直接传递 Url 而无需 urlparse 就可以了。但我想用 urlparse 来做
url = http://xxxx.com:8089/services/search/distributed/peers
提前致谢。
解决方案
pythonrequests
库采用url
纯string
格式。您不能将dictionary
单个 url 组件传递给它。
推荐阅读
- java - 在 selenium 中使用 apache poi 读取 Excel 文件,但尝试在 java 中运行代码时显示 nullpointerException 错误
- recursion - DFS 输出所有匹配元素及其祖先:javascript
- html - 如何使我的文本和第一个 div 垂直对齐?
- python - 如何正确设置分页?
- database - 我无法从我的网站连接到我的 Azure SQL 数据库,但是我可以使用 SSMS 连接到它
- python - 网络抓取班级列表但返回 0 数据?
- javascript - 对输入的javascript执行递归函数
- flutter - Flutter TextField FocusNode没有重新获得焦点[FocusNode“NOT FOCUSABLE”]
- python - 独立于文件扩展名使用 Wand 生成 gif
- arrays - 选择案例语句中的数组是否可能?