You are passing in a string; headers can’t ever be a JSON encoded string, it is always a Python dictionary.
The print results are deceptive; JSON encoded objects look a lot like Python dictionary representations but they are far from the same thing.
The requests API clearly states that headers must be a dictionary:
headers– (optional) Dictionary of HTTP Headers to send with theRequest.
JSON data is something you’d send as content to another server, not something you’d use to communicate with a Python API.
Related Posts:
- How do I format a string using a dictionary in python-3.x?
- How do I lowercase a string in Python?
- Iterating over dictionaries using ‘for’ loops
- How do I get a substring of a string in Python?
- How do I sort a dictionary by value?
- How do I sort a dictionary by value?
- Does Python have a string ‘contains’ substring method?
- How to read a file line-by-line into a list?
- strip(char) on a string
- How do I sort a dictionary by value?
- Check if a given key already exists in a dictionary
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How does collections.defaultdict work?
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- TypeError: not all arguments converted during string formatting python
- Is a Python dictionary an example of a hash table?
- Converting dictionary to JSON
- ‘str’ object does not support item assignment
- How do I merge two dictionaries in a single expression (taking union of dictionaries)?
- How do I append one string to another in Python?
- How do I append one string to another in Python?
- Random string generation with upper case letters and digits
- How can I split and parse a string in Python?
- Python list of dictionaries search
- Updating a dictionary in python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How to read a text file into a string variable and strip newlines?
- unhashable type: ‘dict’ Type Error [duplicate]
- Convert bytes to a string
- How to copy a dictionary and only edit the copy
- How to print like printf in Python3?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How to read a text file into a string variable and strip newlines?
- How can I remove a key from a Python dictionary?
- How to solve dictionary changed size during iteration error?
- DataFrame constructor not properly called
- Python convert tuple to string
- write() versus writelines() and concatenated strings
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Split a string into 2 in Python
- TypeError: ‘dict’ object is not callable
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- Getting key with maximum value in dictionary?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- Getting key with maximum value in dictionary?
- How to check if the string is empty?
- How to find all occurrences of a substring?
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- How do I convert a list of ascii values to a string in python?
- How to check whether a str(variable) is empty or not?
- How can I get dictionary key as variable directly in Python (not by searching from value)?
- Are dictionaries ordered in Python 3.6+?
- How can I remove a key from a Python dictionary?
- Python TypeError: not enough arguments for format string
- append multiple values for one key in a dictionary [duplicate]
- What does the ‘b’ character do in front of a string literal?
- Convert a python dict to a string and back
- How to add a string in a certain position?
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- Delete an element from a dictionary
- How can I concatenate str and int objects?
- What does the ‘b’ character do in front of a string literal?
- How to add multiple values per key in python dictionary
- Get key by value in dictionary
- How to add multiple values to a dictionary key in python?
- Best way to replace multiple characters in a string?
- Convert columns to string in Pandas
- How to delete a character from a string using Python
- Python: Get the first character of the first string in a list?
- Determine the type of an object?
- How to convert string to binary?
- enumerate() for dictionary in python
- Remove the first character of a string
- Reverse / invert a dictionary mapping
- Convert hex to binary
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- Creating 2D dictionary in Python
- How to print a dictionary’s key?
- Converting Dictionary to List?
- How to pretty print nested dictionaries?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Convert a Pandas DataFrame to a dictionary
- Remove all special characters, punctuation and spaces from string
- How to check if a string is a substring of items in a list of strings?
- Best way to replace multiple characters in a string?
- How to index into a dictionary?
- How do I remove a substring from the end of a string?
- In Python, when to use a Dictionary, List or Set?
- How can I splice a string?