#๐ Unicode encode error
45 messages ยท Page 1 of 1 (latest)
@sick sapphire
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
the content you're getting may not be JSON at all
I suggest you check what it actually is
Check both headers Content-Type and Content-Encoding
content-encoding may be absent
and content-type may lie
though it's more likely that you're just getting non-json content like HTML
happened to me more times I can count
What's the url you're using?
if you replace .json() with read(), can you verify that it's actually in JSON format?
.content
oh, that's the way? I don't use requests myself
the error isn't in the json part, but decoding it from utf-8
Encode Error? that's weird though
I wanted the OP to confirm the contents to see what they're really dealing with
yeah, it's apparently .content in requests
I don't use that either ๐
@sick sapphire seeing what the content is would help
emojis should be fine
well, utf-8 has no problem with encoding emojis
but...what is that charmap codec?
I'm more confused it's saying Unicode__Encode__Error.
yeah, that's weird
that above sequence decodes to ๐
@sick sapphire could you show us the traceback?
charmap could be something like cp1252.. it usually says on the next line of the error.
It would be helpful if you showed the full tracback.
!traceback please
Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.
A full traceback could look like:
Traceback (most recent call last):
File "my_file.py", line 5, in <module>
add_three("6")
File "my_file.py", line 2, in add_three
a = num + 3
~~~~^~~
TypeError: can only concatenate str (not "int") to str
If the traceback is long, use our pastebin.
You can do sys.stdout.reconfigure(encoding="utf-8")
when clearly it happened when printing something to the console
I've seen some installs use ascii for stdout for some reason
you can check via sys.stdout.encoding
!e import sys; print(sys.stdout.encoding)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
utf-8
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ Unicode encode error