Python Forum
requests digest auth with netrc
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
requests digest auth with netrc
#1
Hello,
According to the documentation for requests:

netrc Authentication

If no authentication method is given with the auth argument, Requests will attempt to get the authentication credentials for the URL's hostname from the user's netrc file. The netrc file overrides raw HTTP authentication headers set with headers=.

If credentials for the hostname are found, the request is sent with HTTP Basic Auth.


I like to use ~/.netrc with Digest auth not with Basic how can i achieve that.
Reply
#2
Ok at this time Requests does not enable the use of Digest Auth with ~/.netrc

So i came up with simple function do to the job for me

def password_from_netrc(remote_url):
   rec = re.compile(r"https?://(www\.)?")
   url_no_proto = rec.sub('',remote_url).strip().strip('/')
   try:
       auth = netrc.netrc().authenticators(url_no_proto)
   except IOError:
       print('~/.netrc does not exist.')
       quit(1)
   if auth is None:
       print('%s not found in ~/.netrc' % url_no_proto)
       print('example: machine %s login <Username> password <Password>' % url_no_proto)
       quit(1)
   username = (auth[0])
   password = auth[2]
   return username, password
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Configuring requests module to use secondary IP on server for outbound requests mohit 1 6,567 Oct-24-2016, 05:21 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020