I'm receiving this error when trying to decode json:
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Any help will be appreciated.
views.py:
from django.shortcuts import render
import requests
def home(request):
response = requests.get('https://dev-api.prime.com/api/v1/hub/login')
data = response.json()
return render (request, 'home.html', {
'email': data['email'],
'password': data['password']
})
urls.py:
path ('home/', views.home, name="home"),
home.html
{% extends 'main.html' %}
{% block content %}
<h2>API</h2>
<p>Your email is <strong>{{ email }}</strong>, and password <strong>{{ password }}</strong></p>
{% endblock %}
I tried to send POST request from the terminal:
http POST https://dev-api.prime.com/api/v1/hub/login email="[email protected]" password="asssdps"
and get the response I was looking for:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 866
Content-Type: application/json; charset=UTF-8
Date: Wed, 28 Oct 2020 07:09:45 GMT
Server: nginx/1.12.2
Set-Cookie: _language=811f45dc7836f8b3da4c5d04b177501191c20a3f77a46812f864a3bca7d5d3e1a%3A2%3A%7Bi%3A0%3Bs%3A9%3A%22_language%22%3Bi%3A1%3Bs%3A2%3A%22en%22%3B%7D; path=/; HttpOnly
Set-Cookie: _csrf=5f3fb0e6b529660e0a11a97a3fd3e9a85aa3794d20; path=/; HttpOnly
Vary: Accept
X-Debug-Duration: 816
X-Debug-Link: /debug/default/view?tag=5f991938b8410
X-Debug-Tag: 5f991938b8410
X-Frame-Option: SAMEORIGIN
X-Powered-By: PHP/7.2.18
X-UA-Compatible: IE=Edge,chrome=1
X-XSS-Protection: 1
{
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MDM4Njg5ODUsImlzcyI6Imh0dHA6XC9cL2Rldi1hcGkuZGVudGFwcmltZS5jb206ODA5NCIsImF1ZCI6Imh0dHA6XC9cL2Rldi1hcGkuZGVudGFwcmltZS5jb206ODA58",
"complete": false,
"country": "AL",
"date_of_birth": null,
"email": "[email protected]",
"first_name": "somename",
"id": 201,
"last_name": "somename",
"phone": "08865444567",
"role": 10,
"sf_token": "0014H00002dd",
"type_language": "en",
"username": ""
},
"status": 200,
"success": true
}