【发布时间】:2020-04-14 19:09:37
【问题描述】:
我可以执行 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 传递给请求的正确方法,我能够在没有 urlparse 的情况下直接传递 Url 就可以了。但我想用 urlparse 来做
url = http://xxxx.com:8089/services/search/distributed/peers
提前致谢。
【问题讨论】:
-
试试
re = requests.post(http://xxxx.com:8089/services/search/distributed/peers, data=payload, headers=headers)看看是否有效
标签: python python-3.x python-2.7 python-requests