1

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?

yuval
  • 2,848
  • 4
  • 31
  • 51

1 Answers1

0

The server Side is PHP right? You can try use utf8_decode() function. Try and see if this function solve your problem.

$data = utf8_decode($data_from_python);

Check this out: http://php.net/manual/en/function.utf8-decode.php

Vitor Villar
  • 1,855
  • 18
  • 35