pythonjsonpython-requestspostman

API request works in browser, but, doesn't work in Postman or Python requests module


I am trying to request this API: https://iso19139echnap.geocat.live/geonetwork/srv/api/0.1/groups/11864 it works in browser if I enter it as a direct URL, but it doesn't work in Python Request module or in Postman.

Python code looks like the following:

import requests

payload = {
    'username': 'corey',
    'password': 'testing'
}
r = requests.get('https://iso19139echnap.geocat.live/geonetwork/srv/api/0.1/groups/11864')

print(r)
--------------------------------------------------------
returns
<Response [400]>

Solution

  • import requests
    
    url = "https://iso19139echnap.geocat.live/geonetwork/srv/api/0.1/groups/11864"
    
    payload = {}
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-IE,en-GB;q=0.9,en-US;q=0.8,en;q=0.7',
        }
    
    response = requests.request("GET", url, headers=headers, data=payload)
    
    print(response.text)
    

    you have to add accept encoding header

    Add the same in postman also and it works fine

    enter image description here