python3.6.7haskey_python3.6数据分离,读取excal表中的json字符串后,进行get请求报AttributeError: 'str' object has no attri...

我用的数据分离将heades的数据放到了excal表中,在执行代码能打印出来json格式的数据,但是post请求时报AttributeError: 'str' object has no attribute 'items'

以下为excal表中的数据:

{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',

'Accept-Encoding': 'gzip, deflate',

'Accept-Language': 'zh-CN,zh;q=0.9',

'Cache-Control': 'max-age=0',

'Connection': 'keep-alive',

'Cookie': 'blogAppAd_blog7article=1; U_TRS1=0000000e.8eeb7a94.5ad22c7f.660e42af; UOR=www.baidu.com,blog.sina.com.cn,; SINAGLOBAL=114.250.89.255_1523723394.617448; closeNotice_fzp=null; rotatecount=2; U_TRS2=0000000e.f5453d79.5ad2bb18.2d1baa02; ULV=1523759833079:3:3:3::1523723612468; Apache=114.250.89.255_1523759897.98579; dlg680=10; sinaads_blogAppAd_blog7article=1',

'Host': 'blog.sina.com.cn',

'Upgrade-Insecure-Requests': '1',

'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'}

以下为代码:

#!/usr/bin/python# -*- coding: UTF-8 -*-importrequests

importjson

frombase importresult_need

headers = result_need('Sheet1', 0, 0)

print(headers)

url = 'http://blog.sina.com.cn/s/blog_c59abb380102xbbx.html'result =requests.get(url,headers=headers)

print(result.text)

以下为执行后报错信息

"D:\PyCharm 2018.1.1\bin\PycharmProjects\untitled\venv\Scripts\python.exe" "D:/PyCharm 2018.1.1/bin/PycharmProjects/untitled/test/search.py"

{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',

'Accept-Encoding': 'gzip, deflate',

'Accept-Language': 'zh-CN,zh;q=0.9',

'Cache-Control': 'max-age=0',

'Connection': 'keep-alive',

Traceback (most recent call last):

'Cookie': 'blogAppAd_blog7article=1; U_TRS1=0000000e.8eeb7a94.5ad22c7f.660e42af; UOR=www.baidu.com,blog.sina.com.cn,; SINAGLOBAL=114.250.89.255_1523723394.617448; closeNotice_fzp=null; rotatecount=2; U_TRS2=0000000e.f5453d79.5ad2bb18.2d1baa02; ULV=1523759833079:3:3:3::1523723612468; Apache=114.250.89.255_1523759897.98579; dlg680=10; sinaads_blogAppAd_blog7article=1',

'Host': 'blog.sina.com.cn',

'Upgrade-Insecure-Requests': '1',

File "D:/PyCharm 2018.1.1/bin/PycharmProjects/untitled/test/search.py", line 12, in

'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'}

result =requests.get(url,headers=headers)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 72, 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 58, 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 494, in request

prep = self.prepare_request(req)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 437, 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 306, in prepare

self.prepare_headers(headers)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\models.py", line 438, in prepare_headers

for header in headers.items():

AttributeError: 'str' object has no attribute 'items'

Process finished with exit code 1

求大神帮助,感谢

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值