Last active
December 19, 2020 08:44
-
-
Save catichenor/2a62e075bb908b6ff3d0fbc195bd48e7 to your computer and use it in GitHub Desktop.
How to add authentication to a request in many_requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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