I'm having this error while connecting my Django project with Zoho Books via API. From the first function, page will redirect to another URL on that URL an Authorization Code will be there in URL parameter
so I need to access the code in the next function so I could connect my project with Zoho books. Website
thanks in advance for the help
@csrf_exempt
@app.route('/get_details')
def get_details(request):
if request.method == 'POST':
scope = "ZohoBooks.fullaccess.all"
client_id = "1000.####"
# client_secret = "#####"
redirect_uri = "https://admin.####.com/code/"
access_type = "offline"
url = f"https://accounts.zoho.com/oauth/v2/auth?scope={scope}&client_id={client_id}&state=testing&response_type=code&redirect_uri={redirect_uri}&access_type={access_type}".format(scope, client_id, redirect_uri)
webbrowser.open(url)
return redirect(url_for('/open_page/'))
print('redirect is processed ')
else:
return "PLEASE SELECT POST METHOD"
print('method is not post')
@app.route('/code')
def open_page(request, code):
code = request.args.get('code')
if code:
client_id = "1000.#####"
client_secret = "####"
redirect_uri = "https://admin.####.com/code/"
response = requests.post(f"https://accounts.zoho.com/oauth/v2/token?code={code}&client_id={client_id}&client_secret={client_secret}&redirect_uri={redirect_uri}&grant_type=authorization_code".format(code, client_id, client_secret, redirect_uri))
access_token = response.json().get("access_token")
print(access_token)
if access_token:
headers = {'Authorization': 'Zoho-oauthtoken' +access_token}
response = requests.get("https://books.zoho.com/api/v3/invoices?organization_id=#####", headers=headers)
return json.dumps(response.text)
return "Done"
if __name__ == '__main__':
app.run(debug=True)
error file
Internal Server Error: /get_details/
Traceback (most recent call last):
File "D:\aldobi-work-trial\aldobi_env_39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "D:\aldobi-work-trial\aldobi_env_39\lib\site-packages\django\utils\deprecation.py", line 116, in __call__
response = self.process_response(request, response)
File "D:\aldobi-work-trial\aldobi_env_39\lib\site-packages\django\middleware\clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'str' object has no attribute 'get'
Writer is a powerful online word processor, designed for collaborative work.