Python请求代理“str”对象没有属性“get”

2024-05-13 03:31:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用代理执行请求。

我的代码:

import requests
proxies = {'http' '1.1.1.1:1234'}
r = requests.get('https://httpbin.org/ip', proxies=proxies)
print(r.text)

错误:

    no_proxy = proxies.get('no_proxy') if proxies is not None else None
    AttributeError: 'set' object has no attribute 'get'

编辑:

我错过了一场比赛

新代码:

import requests
proxies = {'http': '1.1.1.1:1234'}
r = requests.get('https://httpbin.org/ip', proxies=proxies)
print(r.text)

Tags: no代码texthttpsorgimportipnone
1条回答
网友
1楼 · 发布于 2024-05-13 03:31:20

您的字典中缺少一个:

proxies = {'http': '1.1.1.1:1234'}

如果您有proxies = {'http' '1.1.1.1:1234'},那么proxies实际上是一个set,具有单个值'http1.1.1.1:1234',因此出现错误

相关问题 更多 >