bintry 2018-12-24 09:50 采纳率: 0%
浏览 4088

can't concat str to bytes

import urllib.request
import urllib.parse

url="https://www.baidu.com/s?"
header=urllib.request.HTTPHandler()
opener=urllib.request.build_opener(header)
ser=input("请输入你要查询的内容")
date={
'word' : ser,
}
date=urllib.parse.urlencode(date)
url+=date
print(url)
headers={
'User-Agent' : 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36',
}
req=urllib.request.Request(url,headers)
response=opener.open(req)
print(response)
报错如下:
Traceback (most recent call last):
File "D:/PycharmProjects/search.py", line 18, in
response=opener.open(req)
File "C:\Users\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Users\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 543, in _open
'_open', req)
File "C:\Users\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\MaiBenBen\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\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\MaiBenBen\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\MaiBenBen\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1054, in _send_output
+ b'\r\n'
TypeError: can't concat str to bytes

  • 写回答

3条回答

  • L星火燎原 2018-12-24 02:39
    关注

    原因分析:pandas与python版本不匹配。

    解决方法,更换python版本

    评论

报告相同问题?

悬赏问题

  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路