python-问题总结

1. TypeError: Object of type ‘bytes’ is not JSON serializable

    with open(filename, "rb") as fb:
        image = base64.b64encode(fb.read())
	    data_dict = {
	        "img_base64": image.decode("utf-8")
	    }

	    data = json.dumps(data_dict)
	
	    req = request.Request(URL, data=bytes(data, encoding="utf-8"), headers=HEADERS)
	    res = request.urlopen(req)
	    content = res.read()
	    content = json.loads(content)

2._csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)

#! -*- coding: utf-8 -*-
from contextlib import closing
from urllib import parse
import codecs
import csv
import requests

URL = "xxxxxx"
url = URL + "?" + parse.urlencode(query)

with closing(requests.get(url, headers=HEADERS, stream=True)) as r:
    reader = csv.reader(codecs.iterdecode(r.iter_lines(), 'gbk'))
    for row in reader:
        print(row)

3. ImportError: No module named _sqlite3

python3环境import sqlite3时报错,错误原因时安装python时找不到sqlite3安装目录,可以在python的安装目录的setup.py中看到

sqlite_inc_paths = [

]
tar -xzvf xxxx.gz
cd xxxx
./configure --prefix=/usr/local
make -j
make install 

所以需要重新编译安装sqlite3后,再重新编译安装python.
sqlite3下载:https://www.sqlite.org/download.html

你可能感兴趣的:(编程语言-Python)