爬虫报错:
ValueError: Content-Length should be specified for iterable data of type <class 'dict'> {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'}
原来是写错了,以为记得headers可以省略的
before:
import urllib
url='http://pic40.photophoto.cn/20160723/1155116358658948_b.jpg'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
}
res=urllib.request.Request(url,headers)
response=urllib.request.urlopen(res)
with open('360fj1.jpg','wb')as f:
f.write(response.read())
after:
import urllib
url='http://pic40.photophoto.cn/20160723/1155116358658948_b.jpg'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
}
res=urllib.request.Request(url,headers=headers)
response=urllib.request.urlopen(res)
with open('360fj1.jpg','wb')as f:
f.write(response.read())
headers不能省略