|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
新手调试了3个小时,python版本也和小甲鱼老师用的一样。按照教程视频中一个代码一个代码敲得,不知道为何报错如下信息,有爱心的大侠们帮帮我,不胜感激!!!!
源代码:
import urllib.request
import urllib.parse
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=http://dict.youdao.com/'
data = {'i': 'python', 'keyfrom': 'fanyi.web', 'type': 'AUTO', 'action': 'FY_BY_CLICKBUTTON', 'ue': 'UTF-8', 'doctype': 'json', 'xmlVersion': '1.8', 'typoResult': 'true'}
date = urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url,data)
html = response.read().decode('utf-8')
print(html)
报错信息:
>>>
Traceback (most recent call last):
File "C:\Python34\lib\urllib\request.py", line 1127, in do_request_
mv = memoryview(data)
TypeError: memoryview: dict object does not have the buffer interface
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\python\translate.py", line 7, in <module>
response = urllib.request.urlopen(url,data)
File "C:\Python34\lib\urllib\request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "C:\Python34\lib\urllib\request.py", line 453, in open
req = meth(req)
File "C:\Python34\lib\urllib\request.py", line 1132, in do_request_
data))
ValueError: Content-Length should be specified for iterable data of type <class 'dict'> {'typoResult': 'true', 'keyfrom': 'fanyi.web', 'action': 'FY_BY_CLICKBUTTON', 'i': 'python', 'type': 'AUTO', 'ue': 'UTF-8', 'doctype': 'json', 'xmlVersion': '1.8'} |
|