Skip to content

Instantly share code, notes, and snippets.

@catichenor
Last active December 19, 2020 08:44
Show Gist options
  • Save catichenor/2a62e075bb908b6ff3d0fbc195bd48e7 to your computer and use it in GitHub Desktop.
Save catichenor/2a62e075bb908b6ff3d0fbc195bd48e7 to your computer and use it in GitHub Desktop.
How to add authentication to a request in many_requests
#!/usr/bin/env python3
# How to do Basic authentication with the many_requests library, should work for Digest auth,
# or any other authentication method supported by the asks library.
# many_requests: https://github.com/joshlk/many_requests
# asks library authentication docs: https://asks.readthedocs.io/en/latest/overview-of-funcs-and-args.html#authing
from many_requests import ManyRequests
from asks import BasicAuth
item_list = ["12345", "23456", "34567", "45678", "56789"]
def many_auth_requests(item_list):
user = "username"
password = "password"
responses = ManyRequests(n_workers=5, n_connections=5, json=True)(
method='GET',
auth=BasicAuth((user, password)),
url=['https://some_website.com/api/getitem/{}'.format(item) for item in item_list])
return responses
many_items_data = many_auth_requests(item_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment