我可以执行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
先谢谢了。
答案 0 :(得分:0)
python requests
库采用纯url
格式的string
。您不能通过dictionary
的单个URL组件来传递它。