简体   繁体   English

UnicodeDecodeError Python

[英]UnicodeDecodeError Python

I am trying to build up a network using Networkx library in python. 我正在尝试使用python中的Networkx库建立网络。 Some of the node names are url links. 一些节点名称是URL链接。 For example, one of the urls are ' http://www.everydayhealth.com/health-recipe/summer-vegetable-cr+ \\x8cpes.aspx?pos=3' 例如,其中一个网址是“ http://www.everydayhealth.com/health-recipe/summer-vegetable-cr+ \\ x8cpes.aspx?pos = 3”

I am trying to save the network in gml format and it gives me the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 111: ordinal not in range(128) 我试图将网络保存为gml格式,它给了我以下错误:UnicodeDecodeError:'ascii'编解码器无法解码位置111的字节0xe9:序数不在范围内(128)

Based on the links I read, I know that the url is a 'string' and not a 'unicode'. 根据我阅读的链接,我知道该URL是一个“字符串”而不是一个“ unicode”。 I checked it using type(url). 我使用type(url)进行了检查。 But because it gives me the above error it means it does not contain all ASCII characters. 但是因为它给了我上面的错误,所以它并不包含所有的ASCII字符。 So, I tried the following: 因此,我尝试了以下方法:

u1=url.decode('ascii') It gives me the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 64: ordinal not in range(128) u1 = url.decode('ascii')它给了我以下错误:UnicodeDecodeError:'ascii'编解码器无法解码位置64的字节0x8c:序数不在范围内(128)

How should I go about it? 我应该怎么做? My main purpose is to save this network in a gml format. 我的主要目的是以gml格式保存此网络。 Any help will be appreciated. 任何帮助将不胜感激。

Thank You 谢谢

have you tried to change encoding? 您是否尝试过更改编码? this may help you https://docs.python.org/2/howto/unicode.html 这可能会帮助您https://docs.python.org/2/howto/unicode.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM