requests.auth

Here are the examples of the python api requests.auth taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

Example 1

Project: jottalib
Source File: JFS.py
View license
    def __init__(self, auth=None):
        from requests.auth import HTTPBasicAuth
        self.apiversion = '2.2' # hard coded per october 2014
        self.session = requests.Session() # create a session for connection pooling, ssl keepalives and cookie jar
        self.session.mount('https://',requests.adapters.HTTPAdapter(max_retries=10))
        self.session.stream = True
        if not auth:
            auth = get_auth_info()
        self.username, password = auth
        self.session.auth = HTTPBasicAuth(self.username, password)
        self.session.verify = certifi.where()
        self.session.headers =  {'User-Agent':'jottalib %s (https://github.com/havardgulldahl/jottalib)' % (__version__, ),
                                 'X-JottaAPIVersion': self.apiversion,
                                }
        self.rootpath = JFS_ROOT + self.username
        self.fs = self.get(self.rootpath)

Example 2

Project: lightning-python
Source File: main.py
View license
    def set_basic_auth(self, username, password):
        """
        Set authenatication.
        """
        from requests.auth import HTTPBasicAuth
        self.auth = HTTPBasicAuth(username, password)
        return self

Example 3

Project: lightning-python
Source File: main.py
View license
    def set_basic_auth(self, username, password):
        """
        Set authenatication.
        """
        from requests.auth import HTTPBasicAuth
        self.auth = HTTPBasicAuth(username, password)
        return self

Example 4

Project: UDJ-Server
Source File: geocoders.py
View license
def YahooGeocoder(address, locality, region, postalcode, CONSUMER_KEY, CONSUMER_SECRET):
  import requests
  from requests.auth import OAuth1
  from urllib import quote_plus

  url = u'http://yboss.yahooapis.com/geo/placefinder'
  query_params = {
    'q' : quote_plus(address + ' ' + locality + ' ' + region + ' ' + str(postalcode)),
    'flags' : 'J',
  }


  queryoauth = OAuth1(CONSUMER_KEY, CONSUMER_SECRET)
  response = requests.get(url, params=query_params, auth=queryoauth)


  if response.status_code != 200:
    raise LocationNotFoundError('Response status code was not 200')

  try:
    responseJSON = response.json['bossresponse']
  except:
    raise LocationNotFoundError("Didn't get JSON back")

  if responseJSON['responsecode'] != "200":
    raise LocationNotFoundError('Boss Status code was not 200')

  if responseJSON['placefinder']['count'] == 0:
    raise LocationNotFoundError('Location not found')


  result = responseJSON['placefinder']['results'][0]
  return (float(result['latitude']), float(result['longitude']))

Example 5

Project: UDJ-Server
Source File: geocoders.py
View license
def YahooGeocoder(address, locality, region, postalcode, CONSUMER_KEY, CONSUMER_SECRET):
  import requests
  from requests.auth import OAuth1
  from urllib import quote_plus

  url = u'http://yboss.yahooapis.com/geo/placefinder'
  query_params = {
    'q' : quote_plus(address + ' ' + locality + ' ' + region + ' ' + str(postalcode)),
    'flags' : 'J',
  }


  queryoauth = OAuth1(CONSUMER_KEY, CONSUMER_SECRET)
  response = requests.get(url, params=query_params, auth=queryoauth)


  if response.status_code != 200:
    raise LocationNotFoundError('Response status code was not 200')

  try:
    responseJSON = response.json['bossresponse']
  except:
    raise LocationNotFoundError("Didn't get JSON back")

  if responseJSON['responsecode'] != "200":
    raise LocationNotFoundError('Boss Status code was not 200')

  if responseJSON['placefinder']['count'] == 0:
    raise LocationNotFoundError('Location not found')


  result = responseJSON['placefinder']['results'][0]
  return (float(result['latitude']), float(result['longitude']))

Example 6

Project: mailinabox
Source File: fail2ban.py
View license
def http_test(url, expected_status, postdata=None, qsargs=None, auth=None):
	import urllib.parse
	import requests
	from requests.auth import HTTPBasicAuth

	# form request
	url = urllib.parse.urljoin("https://" + hostname, url)
	if qsargs: url += "?" + urllib.parse.urlencode(qsargs)
	urlopen = requests.get if not postdata else requests.post

	try:
		# issue request
		r = urlopen(
			url,
			auth=HTTPBasicAuth(*auth) if auth else None,
			data=postdata,
			headers={'User-Agent': 'Mail-in-a-Box fail2ban tester'},
			timeout=8,
			verify=False) # don't bother with HTTPS validation, it may not be configured yet
	except requests.exceptions.ConnectTimeout as e:
		raise IsBlocked()
	except requests.exceptions.ConnectionError as e:
		if "Connection refused" in str(e):
			raise IsBlocked()
		raise # some other unexpected condition

	# return response status code
	if r.status_code != expected_status:
		r.raise_for_status() # anything but 200
		raise IOError("Got unexpected status code %s." % r.status_code)

Example 7

Project: mailinabox
Source File: fail2ban.py
View license
def http_test(url, expected_status, postdata=None, qsargs=None, auth=None):
	import urllib.parse
	import requests
	from requests.auth import HTTPBasicAuth

	# form request
	url = urllib.parse.urljoin("https://" + hostname, url)
	if qsargs: url += "?" + urllib.parse.urlencode(qsargs)
	urlopen = requests.get if not postdata else requests.post

	try:
		# issue request
		r = urlopen(
			url,
			auth=HTTPBasicAuth(*auth) if auth else None,
			data=postdata,
			headers={'User-Agent': 'Mail-in-a-Box fail2ban tester'},
			timeout=8,
			verify=False) # don't bother with HTTPS validation, it may not be configured yet
	except requests.exceptions.ConnectTimeout as e:
		raise IsBlocked()
	except requests.exceptions.ConnectionError as e:
		if "Connection refused" in str(e):
			raise IsBlocked()
		raise # some other unexpected condition

	# return response status code
	if r.status_code != expected_status:
		r.raise_for_status() # anything but 200
		raise IOError("Got unexpected status code %s." % r.status_code)