Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError: 'utf-8' #46

Open
complicatedZ opened this issue Jan 9, 2024 · 4 comments
Open

UnicodeDecodeError: 'utf-8' #46

complicatedZ opened this issue Jan 9, 2024 · 4 comments

Comments

@complicatedZ
Copy link

complicatedZ commented Jan 9, 2024

Hey guys,
I've download comets and cometspy and set the env. But I come across a sudden mistake as below, wish someone fix it:)
image
and also a disturbing problem since I have set the env right
Uploading 1704779776814.jpg…

@lancong0714
Copy link

I also have this problem. How did you solve it

@complicatedZ
Copy link
Author

I also have this problem. How did you solve it

I have not figured it out yet. Wish someone share a solution.

@dukovski
Copy link
Contributor

dukovski commented Mar 27, 2024

Sorry, I wasn't aware of this thread. Let's try to solve it. I have seen this problem on systems with codec different than the default one.

Can you tell me what system do you have? Is it Windows, Linux or Mac? Do you know what encoding you have on your system? If yes, follow these instructions:

The error message you're encountering, UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 328: invalid continuation byte, suggests that the byte sequence encountered in your decoding process is not valid UTF-8.

To handle this issue, you can try decoding with a different encoding. Here's how you can modify your code to attempt decoding with a different encoding:

python

try:
decoded_output = self.run_output.decode('utf-8')
except UnicodeDecodeError:
decoded_output = self.run_output.decode('latin-1') # Or any other suitable encoding

This code first tries to decode the self.run_output using UTF-8 encoding. If that fails, it falls back to decoding with the Latin-1 encoding. You can replace 'latin-1' with any other encoding you think might be appropriate, depending on the source of the data.

Keep in mind that blindly choosing an encoding might not always give you the desired results, as the correct encoding depends on the actual data and its origin. It might require some trial and error to find the correct encoding in some cases.

@lancong0714
Copy link

Sorry, I wasn't aware of this thread. Let's try to solve it. I have seen this problem on systems with codec different than the default one.

Can you tell me what system do you have? Is it Windows, Linux or Mac? Do you know what encoding you have on your system? If yes, follow these instructions:

The error message you're encountering, UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 328: invalid continuation byte, suggests that the byte sequence encountered in your decoding process is not valid UTF-8.

To handle this issue, you can try decoding with a different encoding. Here's how you can modify your code to attempt decoding with a different encoding:

python

try: decoded_output = self.run_output.decode('utf-8') except UnicodeDecodeError: decoded_output = self.run_output.decode('latin-1') # Or any other suitable encoding

This code first tries to decode the self.run_output using UTF-8 encoding. If that fails, it falls back to decoding with the Latin-1 encoding. You can replace 'latin-1' with any other encoding you think might be appropriate, depending on the source of the data.

Keep in mind that blindly choosing an encoding might not always give you the desired results, as the correct encoding depends on the actual data and its origin. It might require some trial and error to find the correct encoding in some cases.

I apologize for any inconvenience. As a beginner programmer using the Windows operating system, may I ask whether I should add the code to modify the encoding to the cometspy library itself or to my own code?Could you provide me with a specific operational example? thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants