python-3.x 属性错误:“Retry”对象没有属性“method_whitelist”

fumotvh3  于 2023-05-30  发布在  Python
关注(0)|答案(5)|浏览(316)

尝试运行代码时发生以下错误:

Traceback (most recent call last):

    response = session.post(base_url, params={'query': filename_query})
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 805, in urlopen
    if retries.is_retry(method, response.status, has_retry_after):
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 343, in is_retry
    if not self._is_method_retryable(method):
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 331, in _is_method_retryable
    if self.method_whitelist and method.upper() not in self.method_whitelist:
AttributeError: 'Retry' object has no attribute 'method_whitelist'

有人能帮我吗?

1rhkuytd

1rhkuytd1#

我不知道你的具体情况,因为没有太多的信息。尽管如此,我在ApacheBeam管道中使用requests包时也遇到了同样的错误
问题是,method_whitelist已被弃用,并从urllib3==1.26.0中删除,如发布变更日志中所述
我的解决方案是将urllib版本设置为以前的版本,将urllib3==1.25.11添加到我的requirements.txt

tag5nh1u

tag5nh1u2#

我也遇到过类似的问题。在我的例子中,问题是pyfcm库没有更新。此库用于发送推送通知。我的问题通过更新这个库得到了解决。

pip install pyfcm --upgrade
stszievb

stszievb3#

我通过安装requests==1.26.0urllib3==1.26.2解决了类似的问题。

xggvc2p6

xggvc2p64#

使用allowed_methods代替method_whitelist。后者在某个时候被删除,并被前者取代。

yws3nbqq

yws3nbqq5#

使用allowed_methods代替method_whitelist。后者在某个时候被删除,并被前者取代。
有关Retry对象和现有输入选项的更多信息,请参见relevant urllib3 documentation

相关问题