I send my JSON using urllib.request
on Python 3.
data = {"a": "1"}
req = urllib.request.Request('https://example.com', data=json.dumps(data).encode('utf8'), headers={'Content-Type': 'application/json'})
urllib.request.urlopen(req)
The problem is data=json.dumps(data).encode('utf8')
which converts {"a": "1"}
to the same string with a b
prefix b'{"a": "1"}'
.
I know that in python I can use decode('utf8)
to remove the b
prefix, but I need to be able to do this on the server side, because python 3 forces you to send byte stream data.
I use php as the server side code.
I tried using utf8_decode()
but it doesn't do anything.
How can I remove the b
prefix on the server side code?