python3 pycurl 出现 TypeError: string argument expected, got 'bytes' 解决方案
来源:互联网 发布:java并发最好的书籍 编辑:程序博客网 时间:2024/06/01 12:53
用pycurl请求指定链接并返回结果时出现 TypeError: string argument expected, got 'bytes' 错误
经过排查问题出现在使用StringIO的write方法上,用BytesIO替代StringIO即可解决问题,代码如下:
import pycurlimport jsonfrom io import *try: c = pycurl.Curl() b = StringIO() c.setopt(pycurl.WRITEFUNCTION,b.write) c.setopt(c.URL, 'https://weixin.doviews.com/wxapi') c.setopt(pycurl.SSL_VERIFYPEER, 1) c.setopt(pycurl.SSL_VERIFYHOST, 2) #<TIPS>windows 要指定证书的路径不然会出现
#(77, "SSL: can't load CA certificate file E:\\curl\\ca-bundle.crt") #证书路径就在curl下载的压缩包里面。mac/linux下面可以注释掉。 #c.setopt(pycurl.CAINFO, "E:\curl\ca-bundle.crt") #</TIPS> c.perform() result = b.getvalue().decode("utf-8") print(result)except BaseException as e: print(e)finally: b.close() c.close()
0 0
- python3 pycurl 出现 TypeError: string argument expected, got 'bytes' 解决方案
- TypeError: string argument expected, got 'bytes'
- python3版本 解决PIL图片验证码 string argument expected, got 'bytes' 的问题
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- Python出现: TypeError: expected string or buffer
- TypeError: expected bytes, not str
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- 使用pickle将对象存储到文件中时出现 TypeError: write() argument must be str, not bytes
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: fun() got multiple values for argument 'arg'
- TypeError: concat() got an unexpected keyword argument 'axis'
- 报错TypeError: pool_2d() got an unexpected keyword argument 'ws'
- TypeError: histogram() got an unexpected keyword argument 'new'问题
- TypeError: __init__() got an unexpected keyword argument 'syntax'
- TypeError:__init__() got an unexpected keyword argument 'xxx'
- TypeError: pivot_table() got an unexpected keyword argument 'rows'
- 跨域
- 文本相似性检测----中文分词技术
- 2017第五届中国网络安全大会日程抢鲜版纵览
- 读书笔记_算法第四版(一)
- UIProgressView的简单应用
- python3 pycurl 出现 TypeError: string argument expected, got 'bytes' 解决方案
- CentOS7之开机启动设置
- Javascript闭包(Closure)
- 【sqlserver】【问题解决】Ad Hoc Distributed Queries
- 如何在myeclipse中安装svn图解
- 对slideToggle()的进一步了解
- 给定一个字符串,求它的最长回文子串的长度,并打印出最长回文子串
- CentOS7之Jetty安装配置
- 用图片定位html背景