首页 > 解决方案 > 为什么它显示错误,即 __init()__ 需要 1 个位置参数,但是当我在请求模块的 get 方法中传递 url 时给出了 2 个

问题描述

我正在尝试使用请求模块的 get 方法,但它不起作用。有人可以帮我解决这个问题吗?

import requests

r = requests.get('https://www.python.org')
print(r.status_code)

这是我的错误:

$ python request_testing.py
Traceback (most recent call last):
  File "request_testing.py", line 4, in <module>
    get('http://www.python.org')
  File "C:\Python38\lib\site-packages\requests\adapters.py", line 412, in send
    conn = self.get_connection(request.url, proxies)
  File "C:\Python38\lib\site-packages\requests\adapters.py", line 315, in get_connection
    conn = self.poolmanager.connection_from_url(url)
  File "C:\Python38\lib\site-packages\urllib3\poolmanager.py", line 298, in connection_from_url
    return self.connection_from_host(
  File "C:\Python38\lib\site-packages\urllib3\poolmanager.py", line 245, in connection_from_host
    return self.connection_from_context(request_context)
  File "C:\Python38\lib\site-packages\urllib3\poolmanager.py", line 260, in connection_from_context
    return self.connection_from_pool_key(pool_key, request_context=request_context)
  File "C:\Python38\lib\site-packages\urllib3\poolmanager.py", line 281, in connection_from_pool_key
    pool = self._new_pool(scheme, host, port, request_context=request_context)
  File "C:\Python38\lib\site-packages\urllib3\poolmanager.py", line 213, in _new_pool
    return pool_cls(host, port, **request_context)
  File "C:\Python38\lib\site-packages\urllib3\connectionpool.py", line 197, in __init__
    self.pool = self.QueueCls(maxsize)
TypeError: __init__() takes 1 positional argument but 2 were given

标签: pythonpython-requestsrequesthttp-postget-request

解决方案


推荐阅读