Page 1 of 1

Access HTTP response header

Posted: Fri Jul 16, 2021 12:16 pm
by hotzenklotz
Hi,

I am trying to write a program that fetches some info from the GitHub API. As part of that I would like to access the response headers returned from the GitHub server (particularly the ETAG header for caching/request limits). How is that possible in MicroPython?

So far I have tried using the `urequests` lib which does not seem to support response headers. Is there better way/alternative lib to use? Thanks

Code: Select all

import urequests

url = "https://api.github.com/repos/someorga/somerepo/issues/events?per_page=1&page=0"
headers = {
   "User-Agent": "MicroPython",
   "Authorization": "token abc123",
}

response = urequests.get(url, headers=headers)
print(response.headers)
    

Re: Access HTTP response header

Posted: Fri Jul 16, 2021 1:59 pm
by benalb
I think https://github.com/SpotlightKid/mrequests is what you are looking for, in the examples dir there is a parse_response_headers.py.

Re: Access HTTP response header

Posted: Mon Jul 19, 2021 8:28 am
by hotzenklotz
@benalb Thanks. Looks like the mrequests library is exactly what I am looking for. I will give it a try.