Python:请求有效的urllib3错误
我有以下代码
http = urllib3.PoolManager()
resp = http.request(
"GET",
"https://api.nhs.uk/medicines/aciclovir",
headers={
"subscription-key":"XXX"
}
)
print(resp.data)
响应是:
You don't have permission to access "http://api.nhs.uk/medicines/aciclovir" on this server
为什么它转到http://
地址?
但是,当我使用下面的请求时,
url = "https://api.nhs.uk/medicines/aciclovir"
payload={}
headers = {
'subscription-key': 'XXX'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
有什么建议是成功的吗?
更新1
这是正在执行错误发生的确切代码,是的,它确实显示了http://
error
更新2
urllib3
Listening on 0.0.0.0 7777
Connection received on *** 50054
GET / HTTP/1.1
Host: ***:7777
Accept-Encoding: identity
subscription-key: xxx
User-Agent: python-urllib3/1.26.9
请求
Listening on 0.0.0.0 7777
Connection received on *** 50095
GET / HTTP/1.1
Host: ***:7777
User-Agent: python-requests/2.28.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
subscription-key: xxx
I have the following code
http = urllib3.PoolManager()
resp = http.request(
"GET",
"https://api.nhs.uk/medicines/aciclovir",
headers={
"subscription-key":"XXX"
}
)
print(resp.data)
The response is:
You don't have permission to access "http://api.nhs.uk/medicines/aciclovir" on this server
Why has it gone to a http://
address?
However when I use requests as below, it's a success
url = "https://api.nhs.uk/medicines/aciclovir"
payload={}
headers = {
'subscription-key': 'XXX'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Any suggestions?
UPDATE 1
This is the exact code that is being executed for the error to happen which yes, it does show a http://
error
UPDATE 2
urllib3
Listening on 0.0.0.0 7777
Connection received on *** 50054
GET / HTTP/1.1
Host: ***:7777
Accept-Encoding: identity
subscription-key: xxx
User-Agent: python-urllib3/1.26.9
requests
Listening on 0.0.0.0 7777
Connection received on *** 50095
GET / HTTP/1.1
Host: ***:7777
User-Agent: python-requests/2.28.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
subscription-key: xxx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 https://stackoverflow.com/users/240443/amadan 问题是服务器不喜欢服务器Urllib3提供的默认用户代理字符串
更改它,甚至只是分解
python-urllib
字符串,例如pyxthon-urllib
使它起作用,我在他们的支持下进行了此操作
With thanks from https://stackoverflow.com/users/240443/amadan the problem was that the server does not like the default user agent string supplied by urllib3
Changing it or even just breaking up the
python-urllib
string such aspyXthon-urllib
makes it workI have took this up with their support