I am trying to build up a network using Networkx library in python. Some of the node names are url links.
For example, one of the urls are '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)
Based on the links I read, I know that the url is a 'string' and not a 'unicode'. I checked it using type(url). But because it gives me the above error it means it does not contain all ASCII characters. 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)
How should I go about it?
My main purpose is to save this network in a gml format. 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
Related
I'm trying to read a csv file written in arabic, this is the code i'm using:
data = pd.read_csv("/Users/User/Downloads/AJGT.csv",encoding='utf-8')
sentiment = np.array(data.drop('Feed', axis =1).values)
feed = np.array(data.drop('Sentiment', axis =1).values)
print(sentiment)
print(feed)
however i'm getting the following error
'utf-8' codec can't decode byte 0xa0 in position 15456: invalid start byte
I would appreciate any help
Thank you!
Try encoding='ISO-8859-1'. This worked for me, as I got similar error.
Does anybody know how to decode the NAV_PVT message in python?
I tried the UTF-8 but it I get this error message:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte
I can't find the right decode format.
You should read the file as binary, because it is binary. UBlox has a nice documentation on various formats/protocols. Check them
E.g. https://www.u-blox.com/sites/default/files/products/documents/u-blox8-M8_ReceiverDescrProtSpec_%28UBX-13003221%29.pdf page 332. Is this what you are looking for?
Or if you were using some libraries, you should check such documentation. But I assume or you mixed up the binary with ascii version, or you are just using the binary protocol.
I'm getting a UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 24245: ordinal not in range(128) on multiple files, for all of which the position given is basically the end of the file. Chardet.detect() gives me ASCII as the codec with 1.0 confidence.
Does anyone know what encoding this should probably be? This file was written in windows so I assume that has something to do with it.
Edit: Removed hex dump.
I'm facing issues to decode the following hex string in python 3.4:
b'"\x00\x08\x00\x83\x80\x00\x00\x00\x86\x11\x1dBA\x8c\xdb\xc0\\p\xfe#NR09G06654\x00\x00\x00'
I'm trying with a simple:
data = b'"\x00\x08\x00\x83\x80\x00\x00\x00\x86\x11\x1dBA\x8c\xdb\xc0\\p\xfe#NR09G06654\x00\x00\x00'
print(data.decode('ascii'))
But I am getting the following error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 4: ordinal not in range(128)
I have also tried to change to UTF-8
print(data.decode('utf-8'))
But with no success as the error is:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 4: invalid start byte
I have no clue what the problem could be.
There are many communication protocols for GPS devices. A lot of devices use NMEA0183, but that is a plain text protocol and this is clearly not plain text.
If you're not running ms-windows, you should check if your GPS is supported by gpsd. It translates the signals from the GPS into something understandable. It has Python bindings available.
I'm trying to read in a response from a REST API, parse it as JSON and write the properties to a CSV file.
It appears some of the characters are in an unknown encoding and can't be converted to strings when they're written out to the CSV file:
'ascii' codec can't encode character u'\xf6' in position 15: ordinal not in range(128)
So, what I've tried to do is follow the answer by "agf" on this question:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)
I added a call to unicode(content).encode("utf-8") when my script reads the contents of the response:
obj = json.loads(unicode(content).encode("utf-8"))
Now I see a exceptions.UnicodeDecodeError on this line.
Is Python attempting to decode "content" before encoding it as utf-8? I don't quite understand what's going on. There is no way to determine the encoding of the response since the API I'm calling doesn't set a Content-Type header.
Not sure how to handle this. Please advise.