Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Unicode参数应为PYQRCODE_Python 2.7_Svg_Unicode - Fatal编程技术网

Python 2.7 Unicode参数应为PYQRCODE

Python 2.7 Unicode参数应为PYQRCODE,python-2.7,svg,unicode,Python 2.7,Svg,Unicode,通过以下操作,将生成内存中的映像: url = pyqrcode.create(user.get_totp_uri()) stream = StringIO() url.svg(stream, scale=3) return stream.getvalue().encode('utf-8'), 200, { 'Content-Type': 'image/svg+xml', 'Cache-Control': 'no-cache, no-store, must-revalidate'

通过以下操作,将生成内存中的映像:

url = pyqrcode.create(user.get_totp_uri())
stream = StringIO()
url.svg(stream, scale=3)
return stream.getvalue().encode('utf-8'), 200, {
    'Content-Type': 'image/svg+xml',
    'Cache-Control': 'no-cache, no-store, must-revalidate',
    'Pragma': 'no-cache',
    'Expires': '0'}
我得到以下错误:

File "E:\Data\pathsdb\flask\lib\site-packages\pyqrcode\builder.py", line 1118, in _svg
write_bytes(b'<?xml version="1.0" encoding="UTF-8"?>\n')
TypeError: unicode argument expected, got 'str'
文件“E:\Data\pathsdb\flask\lib\site packages\pyqrcode\builder.py”,第1118行,在svg中
写入字节(b'\n')
TypeError:应为unicode参数,得到'str'
有人知道我做错了什么吗

已解决:

使用以下代码:

url = pyqrcode.create(user.get_totp_uri())
stream = BytesIO()
url.svg(stream, scale=3)
return stream.getvalue(), 200, {
    'Content-Type': 'image/svg+xml',
    'Cache-Control': 'no-cache, no-store, must-revalidate',
    'Pragma': 'no-cache',
    'Expires': '0'}
应该使用BytesIO和drop编码