2

I have been trying to make this work for a while.. driving me crazy.

When I try to send POST request to my django app with Hebrew text, it stores the Hebrew text as ???????.

I thought it might be a problem in my postgres database, but its Encoding is UTF-8, and also, when I access the table entries manually, I can change the text to Hebrew and its fine.

What am I doing wrong? How can send POST requests with Hebrew text and store it successfully in the DB??

UPDATE: SOLVED

Apparently, my mistake was so simple and annoying...

In the android app, when you set the params, I did this:

se = new StringEntity(obj.toString());

When I changed my code and added the UTF_8, it solved the issue:

se = new StringEntity(obj.toString(), HTTP.UTF_8);

Just needed to add the UTF_8 Encoding..

Ofek Agmon
  • 5,040
  • 14
  • 57
  • 101
  • Possible duplicate of [decoding and encoding Hebrew string in Python](http://stackoverflow.com/questions/29850912/decoding-and-encoding-hebrew-string-in-python) – JMzance Dec 13 '15 at 14:15

1 Answers1

0

Are you using python 2 or python 3? In python 2 literal strings are not literals. You have to explicitly cast them as unicode like this:

u'Stuff'

See here for more details Unicode literals that work in python 3 and 2

You can import that one feature from python 3 using this too

http://python-future.org/unicode_literals.html

This also seems relevant to your problem:

decoding and encoding Hebrew string in Python

Community
  • 1
  • 1
JMzance
  • 1,704
  • 4
  • 30
  • 49
  • I am using python 3.4 – Ofek Agmon Dec 13 '15 at 14:18
  • 1
    I would check by running a local server with django (./manage.py runserver) and then sending some example posts from a browser. You can then print out what your Django view is receiving immediately as you enter your django end-point and see if the problem is there or if something is going wrong when you put that in your database – JMzance Dec 13 '15 at 14:20
  • thanks! I think that helped.. now what is happening is: if I POST from my android app to django - it stores the hebrew string as ????, BUT - I tried to post from chrome POSTMAN - and it works! it stores the String in hebrew. the weird thing is I also check the data right before I send it from the app - and its in hebrew.. where is the problem?? – Ofek Agmon Dec 13 '15 at 14:54
  • I would thing then then problem is that your android app is failing to encode the utf-8 Hebrew (it's probably just trying to use normal ascii) so its a problem with the app and not your Django project/your postgres DB – JMzance Dec 13 '15 at 16:11
  • Yes you are right:) see my updated question with the solution – Ofek Agmon Dec 13 '15 at 16:13
  • Nice one. Remember to close off the question too. – JMzance Dec 13 '15 at 16:17
  • close it..? when I click "close" which option should I go with? there is no "the question has been answered" option. – Ofek Agmon Dec 13 '15 at 16:28
  • You normally select an answer but I dont know if this is relevant now – JMzance Dec 13 '15 at 16:31