我在GET请求中传递的标头变量出现属性错误

时间:2019-04-29 15:53:00

标签: python get attributeerror

当我尝试传递用于获取请求的标头时,我得到了AttributeError。

auth {"APIUsername":"username","APIPassword":"password"}

response = requests.get(URL, headers=auth, verify=False)

我尝试用单引号将auth标头使用,它似乎正在工作。但是我的凭据是从其他地方检索到的,并且检索到的对象中带有双引号。

Traceback (most recent call last):
  File "C:\Users\Administrator\Downloads\wss_logs_test4.py", line 102, in <module>
    response = requests.get(URL, headers=auth, verify=False)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\models.py", line 314, in prepare
    self.prepare_headers(headers)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\models.py", line 446, in prepare_headers
    for header in headers.items():
AttributeError: 'str' object has no attribute 'items'

0 个答案:

没有答案