Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

request.body django

In Python 3.0 to Python 3.5.x, json.loads() will only accept a unicode string, so you must decode request.body (which is a byte string) before passing it to json.loads().

body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
content = body['content']
In Python 3.6, json.loads() accepts bytes or bytearrays. Therefore you shouldn't need to decode request.body (assuming it's encoded in UTF-8, UTF-16 or UTF-32).
Comment

PREVIOUS NEXT
Code Example
Python :: smtp email template 
Python :: tkinter starter code 
Python :: python3 hello world 
Python :: How do you find the missing number in a given integer array of 1 to 100? 
Python :: First Unique Character in a String in python 
Python :: accessing data on django sessionstore 
Python :: python close browser 
Python :: hmac in python 
Python :: python dataframe shape 
Python :: pandas to_csv no index 
Python :: tensorfow list devices 
Python :: create a df in pandas 
Python :: pandas series to numpy array 
Python :: initialize dictionary with empty lists 
Python :: print value of tensor 
Python :: Learn python 3 the hard way by by Zed Shaw 
Python :: generic type python 
Python :: last element in list py 
Python :: python count total no of word in a text 
Python :: how to make a for loop increment by 2 in python 
Python :: show image python 
Python :: python filter list of strings 
Python :: create virtual env 
Python :: time now random seed python 
Python :: dataframe choose random 
Python :: reset django database 
Python :: khan academy 
Python :: ascii to decimal python 
Python :: how to add element at first position in array python 
Python :: how to delete a csv file in python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =