Created
April 20, 2018 07:14
-
-
Save ojarva/3d1ffc71e9570e7d824eaedca6896a00 to your computer and use it in GitHub Desktop.
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
import requests | |
class RequestsTest(requests.Session): | |
def __init__(self): | |
super().__init__() | |
self.headers["accept"] = "application/json" | |
self.params["your_api_key_here"] = "my_api_key" | |
def get_with_params(self, params): | |
print(self.get("https://httpbin.org/get", params=params).text) | |
def get_with_params_fixed(self, params): | |
if isinstance(params, list): | |
for k, v in self.params.items(): | |
params.append((k, v)) | |
print(self.get("https://httpbin.org/get", params=params).text) | |
a = RequestsTest() | |
print("Send a dict of params") | |
a.get_with_params({"foo": 1}) # Works fine | |
print("Send a list of params") | |
a.get_with_params([("foo", 1), ("foo", 2)]) # Does not send api key | |
print("Send a list of params with fixed version") | |
a.get_with_params_fixed([("foo", 1), ("foo", 2)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment