bug: error message "JSON parse error..." after REST-query to add-to-cart?format=json
See original GitHub issueenvironment: OS xUbuntu 18.04.4; Python 3.6.9; Django 3.0.8; django-shop 1.2.2 (installed according to instructions https://django-shop.readthedocs.io/en/latest/tutorial/intro.html) STR:
- get cookie-values csrftoken and sessionid adding 1 product to cart in browser and parsing them from headers of corresponding http-request
- execute Python-code (adding 1 products unit to existing cart according to instruction 17.2.3.3. Add Product to Cart)
import httplib2
from urllib.parse import urlencode
h = httplib2.Http('.cache')
data = {
"quantity": 1,
"product": 15,
"product_code": "1004"
}
data = urlencode(data)
response, content = h.request('http://localhost:8000/catalog/smart-cards/sdxc-card-64gb/add-to-cart?format=json','POST',data,headers={'Content-Type':'application/json','accept':'application/json','Cookie':'csrftoken=3hoZkpJNer2kSNaDgO3nOa8r2fLNl6KiwtMJDCW5pbDN9jELORM2dDIYCnE8wwew;sessionid=2k0t3edvimyud5acdpvt71e5dda7jod7'})
print("response.status - {0}".format(response.status))
print("response.items() - {0}".format(response.items()))
print("content - {0}".format(content))
AR: content - b’{“detail”:“JSON parse error - Expecting value: line 1 column 1 (char 0)”}’ ER: understandable error message in the response body
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >Error while parsing JSON Response in REST API Post call
When I invoke the same REST method through the UI, it is raising a parsing error. I switched to returning a JSON String...
Read more >JSON.parse error on a seemingly valid JSON [duplicate]
The error is a result of data being an object, not JSON. You don't need to parse anything; it is already a JavaScript...
Read more >In rest message getting {"detail":"JSON parse error - ServiceNow
Hi, I am getting {"detail":"JSON parse error - Invalid \\escape: line 11 column 31 (char 359)\nPossible cause: trailing comma."}
Read more >JSON parse error when displaying validation error in tree mode
Using schema and json provided below, I get a JSON parse error, and a broken tree view. Failed to parse JSON schema: SyntaxError:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
as far as I know, JSON data must be transferred (and will be received) as byte-stream, not string. Maybe you have to check this as well.
before sending a dict as JSON, you have to stringify it.