Python Forum
requests digest auth with netrc
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
requests digest auth with netrc
#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


Messages In This Thread
requests digest auth with netrc - by fstefanov - Jun-05-2017, 12:43 AM
RE: requests digest auth with netrc - by fstefanov - Jun-05-2017, 08:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Configuring requests module to use secondary IP on server for outbound requests mohit 1 6,663 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