0

Background: I am developing an application based on codeigniter-4 to host my APIs', react native for mobile-application and python3 scripts to upload data to my server (ci4-api) from my desktop.

What is working: I can request/connect to server via POSTMAN app, also I can connect to server from react native app as follows, both shows successful

response = await fetch(url, {method: 'GET'});

what is not working: when I request by using python requests it throws 406 error, code below

import requests
from requests.exceptions import HTTPError 

# url is removed 

try:
    response = requests.get(url)
    response.raise_for_status()
except HTTPError as http_err:
    print(f'HTTP error occurred: {http_err}')
except Exception as err:
    print(f'Other error occured: {err}')
else:
    print('Success')

out >> HTTP error occurred: 406 Client Error: Not Acceptable for url:

In codeigniter I am using get method in routes. Please let me know your feedback why it fails in python

I have also tried POST method, it is not inserting any data to database in python

payload = { 'id':'sdfr234', 'name' : 'An 23', 'phoneNumber' : '96529', 'password':'qwerty' } 
headers = {'Content-Type': 'application/json', 'Accept':'application/json' } 
response = requests.post(url, headers = headers, json=payload)
sadath
  • 53
  • 5
  • Does this answer your question? [What is "406-Not Acceptable Response" in HTTP?](https://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http) – 3nws Aug 03 '22 at 10:38
  • I tried to use `post` instead of `get` , also added the headers and then checked the database. Getting same message 406, more over no data added to database. `payload = { 'id':'sdfr234', 'name' : 'An 23', 'phoneNumber' : '96529', 'password':'qwerty' }` `headers = {'Content-Type': 'application/json', 'Accept':'application/json' }` response = requests.post(url, headers = headers, json=payload)` – sadath Aug 03 '22 at 15:51
  • Instead of `requests` when I use `http.client`, I get response as I expected. I don't know the exact issue with `requests` – sadath Aug 04 '22 at 13:55

0 Answers0