Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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
Python2到Python3 futurize内置str_Python_Django_Python 3.x - Fatal编程技术网

Python2到Python3 futurize内置str

Python2到Python3 futurize内置str,python,django,python-3.x,Python,Django,Python 3.x,我正在使用futurize将django应用程序从Python 2转换为Python。 我目前正在为未来的建筑设计未来。在测试中的以下代码集中: response = str(self.client.get(self.url)) 我得到以下错误: UnicodeDecodeError:“ascii”编解码器无法解码位置3261:序号不在范围(128)中的字节0xe2,测试失败 但是,当我删除以下导入时: from builtins import str 测试通过了。我尝试使用decode()

我正在使用futurize将django应用程序从Python 2转换为Python。 我目前正在为未来的建筑设计未来。在测试中的以下代码集中:

response = str(self.client.get(self.url))
我得到以下错误:
UnicodeDecodeError:“ascii”编解码器无法解码位置3261:序号不在范围(128)中的字节0xe2
,测试失败

但是,当我删除以下导入时:

from builtins import str
测试通过了。我尝试使用decode()函数,但得到了相同的错误。
哪里会出错?

您不想从回复中选择一组特定的内容吗?例如除此之外,我认为这不一定是一个好主意

response = self.client.get(self.url)
if response.is_client_error() or response.is_server_error():
    # do failure
else:
    content = response.content
    # check content
如果你想把它转换成一个字符串,我不建议你使用它,但是一个良好的兼容性是可能的

response = self.client.get(self.url).__repr__() 
# or "even less recommended reason being is it will fail for eval()"
response = self.client.get(self.url).__str__()