|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import urllib.request
- import urllib.parse
- url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
- data = {}
- data["i"] = 'i love fishc.com'
- data["from"] = 'AUTO'
- data["to"] = 'AUTO'
- data["smartresult"] = 'dict'
- data["client"] = 'fanyideskweb'
- data["salt"] = '15559890256985'
- data["sign"] = '602f385b29eb728e1493d726bee416d9'
- data["ts"] = '1555989025698'
- data["bv"] = '7aa7fb563107e590a52b125bb19c7b5a'
- data["doctype"] = 'json'
- data["version"] = '2.1'
- data["keyfrom"] = 'fanyi.web'
- data["action"] = 'FY_BY_REALTlME'
- urllib.parse.urlencode(data).encode("utf-8")
- response = urllib.request.urlopen(url, data)
- html = response.read().decode("utf-8")
- print(html)
复制代码
报错信息:
- =============== RESTART: C:\Users\qingming_wu\Desktop\test.py ===============
- Traceback (most recent call last):
- File "C:\Users\qingming_wu\Desktop\test.py", line 25, in <module>
- response = urllib.request.urlopen(url, data)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 222, in urlopen
- return opener.open(url, data, timeout)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 525, in open
- response = self._open(req, data)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 543, in _open
- '_open', req)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
- result = func(*args)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 1345, in http_open
- return self.do_open(http.client.HTTPConnection, req)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 1317, in do_open
- encode_chunked=req.has_header('Transfer-encoding'))
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1229, in request
- self._send_request(method, url, body, headers, encode_chunked)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1275, in _send_request
- self.endheaders(body, encode_chunked=encode_chunked)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1224, in endheaders
- self._send_output(message_body, encode_chunked=encode_chunked)
- File "C:\Users\qingming_wu\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1054, in _send_output
- + b'\r\n'
- TypeError: can't concat str to bytes
复制代码
这个应该怎么解决啊?这个好像是编码问题吧,不好解决啊。
|
|