Starting with Requests version 2.4.2, you can use the json=
parameter (which takes a dictionary) instead of data=
(which takes a string) in the call:
>>> import requests >>> r = requests.post('http://httpbin.org/post', json={"key": "value"}) >>> r.status_code 200 >>> r.json() {'args': {}, 'data': '{"key": "value"}', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '16', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.4.3 CPython/3.4.0', 'X-Request-Id': 'xx-xx-xx'}, 'json': {'key': 'value'}, 'origin': 'x.x.x.x', 'url': 'http://httpbin.org/post'}
Related Posts:
- Why am I seeing “TypeError: string indices must be integers”?
- How to prettyprint a JSON file?
- pandas read_json: “If using all scalar values, you must pass an index”
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Converting dictionary to JSON
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to parse data in JSON format?
- ImportError: No module named requests
- Importing requests module does not work
- json.dumps vs flask.jsonify
- TypeError: unhashable type: ‘dict’, when dict used as a key for another dict
- is not JSON serializable
- How to make a class JSON serializable
- Convert a python dict to a string and back
- TypeError: Object of type ‘bytes’ is not JSON serializable
- Python ValueError: No JSON object could be decoded
- Python error load JSON code of google API
- Return JSON response from Flask view
- Max retries exceeded with URL in requests
- How to overcome “datetime.datetime not JSON serializable”?
- Python/Json:Expecting property name enclosed in double quotes
- Displaying better error message than “No JSON object could be decoded”
- JSON to pandas DataFrame
- Python error load JSON code of google API
- Using headers with the Python requests library’s get method
- Using headers with the Python requests library’s get method
- Displaying better error message than “No JSON object could be decoded”
- ImportError: No module named ‘Queue’
- Displaying better error message than “No JSON object could be decoded”
- Converting XML to JSON using Python?
- Download large file in python with requests
- How to get JSON from webpage into Python script
- Loading a file with more than one line of JSON into Pandas
- What is the difference between json.load() and json.loads() functions
- How to convert an XML string to a dictionary?
- NumPy array is not JSON serializable
- ValueError: Expected object or value when reading json as pandas dataframe
- Getting
with Python http requests instead of INT - How to use cookies in Python Requests
- Python Requests – No connection adapters
- how to read json object in python
- JSON object must be str, bytes or bytearray, not dict
- How to prettyprint a JSON file?
- Unable to resolve ‘requests’. IntelliSense may be missing for this module. Visual Studio/Python
- Can I set max_retries for requests.request?
- TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
- Python requests SSL error – certificate verify failed
- Loading and parsing a JSON file with multiple JSON objects
- set object is not JSON serializable
- dump() missing 1 required positional argument: ‘fp’ in python json
- TypeError: the JSON object must be str, not ‘bytes’
- How to get POSTed JSON in Flask?
- python capitalize first letter only
- Is there a short contains function for lists?
- ImportError: No module named pandas. Pandas installed pip
- How to Execute a Python Script in Notepad++?
- ValueError: operands could not be broadcast together with shapes (5,) (30,)
- appending list but error ‘NoneType’ object has no attribute ‘append’
- Using Python 3 in virtualenv
- Permission denied error by installing matplotlib
- Python equivalent of a given wget command
- How to find list intersection?
- Error while Executing jupyter notebook: [Errno 2] No such file or directory
- ValueError: max() arg is an empty sequence
- How do I insert a JPEG image into a python Tkinter window?
- Use a.any() or a.all()
- What is the difference between Spyder and Jupyter?
- What is the maximum recursion depth in Python, and how to increase it?
- enumerate() for dictionary in python
- How to convert a PIL Image into a numpy array?
- How to get autocomplete in jupyter notebook without using tab?
- numpy with python: convert 3d array to 2d
- Create 3D array using Python
- Is it possible to ignore one single specific line with Pylint?
- Print list without brackets in a single row
- Get first row value of a given column
- AttributeError: ‘module’ object has no attribute
- In Python How can I declare a Dynamic Array
- Python module for converting PDF to text
- from sys import argv – what is the function of “script”
- How to properly ignore exceptions
- How to print instances of a class using print()?
- How to filter Pandas dataframe using ‘in’ and ‘not in’ like in SQL
- What does the Ellipsis object do?
- How to concatenate items in a list to a single string?
- python pip on Windows – command ‘cl.exe’ failed
- pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
- Extract part of a regex match
- Python “SyntaxError: Non-ASCII character ‘\xe2’ in file”
- Rename specific column(s) in pandas
- How to create a numpy array of lists?
- Scikit-learn GridSearch giving “ValueError: multiclass format is not supported” error
- Convert R code into Python code using rpy2
- PIL: DLL load failed: specified procedure could not be found
- How do I add two sets?
- How to count the number of files in a directory using Python
- Counting array elements in Python
- IPython, “name ‘plt’ not defined”
- ‘pyuic5’ is not recognized as an internal or external command