response.read() returns an instance of bytes while StringIO is an in-memory stream for text only. Use BytesIO instead. The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data resp…
#########sample########## sqlite3.OperationalError: Could not decode to UTF-8 column 'logtype' with text 将 with connection.cursor() as c: c.execute("select id,name from district_info where p_id=0") provinces = c.fetchall() 调整为 con = sqlite3.conn…
Python3.x:报错POST data should be bytes, an iterable of bytes 问题: python3.x:报错 POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str. 原因: # 组装GET方法的请求 request = urllib2.Request(url, data, headers) 其中的data需要转为utf-8…
python3下,利用hash值对字符串进行md5加密时报错:TypeError: Unicode-objects must be encoded before hashing 原因是:python3跟python2区别:python3下字符串为Unicode类型,而hash传递时需要的是utf-8类型,因此,需要类型转换调用函数时,将字符串进行类型转换 import hashlib def get_md5(s): m = hashlib.md5() m.update(s) r…
*字符串不能更改值 数据类型字符串str | capitalize(...) 返回字符串中第一个字母大写 | S.capitalize() -> str | | Return a capitalized version of S, i.e. make the first character | have upper case and the rest lower case. >>> str1='i am chinese' >&g…
import re from common_p3 import download def crawl_sitemap(url): sitemap = download(url) links = re.findall('<loc>(.*?)</loc>',sitemap) print('links=',links) for link in links: print('link=',link) html = download(link) return crawl_sitemap('ht…