I am looking for a way to send a zipfile to the client that is generated from a requests response. In this example, I send a JSON string to a URL which returns a zip file of the converted JSON string. But my zip file is empty and the error returned by flask is Answer You should return the file
Tag: json
Loading initial data with Django 1.7+ and data migrations
I recently switched from Django 1.6 to 1.7, and I began using migrations (I never used South). Before 1.7, I used to load initial data with a fixture/initial_data.json file, which was loaded with the python manage.py syncdb command (when creating the database). Now, I started using migrations, and this behavior is deprecated : If an application uses migrations, there is
Python3: JSON POST Request WITHOUT requests library
I want to send JSON encoded data to a server using only native Python libraries. I love requests but I simply can’t use it because I can’t use it on the machine which runs the script. I need to do it without. My server is a local WAMP server. I always get an urllib.error.HTTPError: HTTP Error 500: Internal Server Error
How to get sorted list inside a dictionary with json.dumps()
I have the following problem: having a python dictionary like the following: I would like to obtain an ordered json object such as: At the moment I use the following: But the two list inside my object are not sorted, and I get: probably because the custom JSONEncoder skips a type that already knows how to manage (list). UPDATE Martijn
Flask, setting JSON in a cookie, and decoding it on the client (in javascript)
I’m setting a cookie in Flask like follows : If i print json.dumps(someObject) on the server I get : On the client side it becomes : I want to decode it on a javascript client what format is it exactly ? I’d like to decode it and pass it to angular.fromJson(), it looks like there is at least unescaping (of
UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte
I am using Python-2.6 CGI scripts but found this error in server log while doing json.dumps(), Here , __getdata() function returns dictionary {} . Before posting this question I have referred this of question os SO. UPDATES Following line is hurting JSON encoder, I got a temporary fix for it But I am not sure is it correct way to
how to hash a “json” nested dictionary identically in Python and JavaScript?
What’s the best way to consistently hash an object/dictionary that’s limited to what JSON can represent, in both JavaScript and Python? What about in many different languages? Of course there are hash functions implemented consistently in many different languages that take a string, but to hash an object you have to convert it to a string representation first. I want
django, “is not JSON serializable” when using ugettext_lazy?
I have this in my views.py Since I start using this import: from django.utils.translation import ugettext_lazy as _ at this line: message = _(‘This is a test message’) I get this error: Why? What am I doing wrong? Answer You can also create you own JSON encoder that will force __proxy__ to unicode. From https://docs.djangoproject.com/en/1.8/topics/serialization/ So now your code can
how to delete json object using python?
I am using python to delete and update a JSON file generated from the data provided by user, so that only few items should be stored in the database. I want to delete a particular object from the JSON file. My JSON file is: I want to delete the JSON object with ename mark. As I am new to python
Saving UTF-8 texts with json.dumps as UTF-8, not as a u escape sequence
Sample code (in a REPL): Output: The problem: it’s not human readable. My (smart) users want to verify or even edit text files with JSON dumps (and I’d rather not use XML). Is there a way to serialize objects into UTF-8 JSON strings (instead of uXXXX)? Answer Use the ensure_ascii=False switch to json.dumps(), then encode the value to UTF-8 manually: