Access HTTP response header

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
hotzenklotz
Posts: 2
Joined: Fri Jul 16, 2021 12:10 pm

Access HTTP response header

Post by hotzenklotz » Fri Jul 16, 2021 12:16 pm

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)
    

User avatar
benalb
Posts: 25
Joined: Fri May 19, 2017 1:23 pm

Re: Access HTTP response header

Post by benalb » Fri Jul 16, 2021 1:59 pm

I think https://github.com/SpotlightKid/mrequests is what you are looking for, in the examples dir there is a parse_response_headers.py.

hotzenklotz
Posts: 2
Joined: Fri Jul 16, 2021 12:10 pm

Re: Access HTTP response header

Post by hotzenklotz » Mon Jul 19, 2021 8:28 am

@benalb Thanks. Looks like the mrequests library is exactly what I am looking for. I will give it a try.

Post Reply