Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Set Content-Type as application/json in requests #159

Merged
merged 3 commits into from
Mar 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions vortexasdk/retry_session.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from requests import Session, Response
from requests import Response, Session
from requests.adapters import HTTPAdapter
from urllib3 import Retry


# Inspired by https://www.peterbe.com/plog/best-practice-with-retries-with-requests
def _requests_retry_session(
retries=6,
backoff_factor=1,
status_forcelist=(500, 502, 504),
session=None,
retries=6,
backoff_factor=1,
status_forcelist=(500, 502, 504),
session=None,
) -> Session:
"""Instantiate a session with Retry backoff."""
session = session or Session()
Expand All @@ -31,11 +31,14 @@ def _requests_retry_session(
return session


_headers = {"Content-Type": "application/json"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If this is a global constant, convention is to set it as _HEADERS at the top of the file



def retry_get(*args, **kwargs) -> Response:
with _requests_retry_session() as s:
return s.get(*args, **kwargs)
return s.get(headers=_headers, *args, **kwargs)


def retry_post(*args, **kwargs) -> Response:
with _requests_retry_session() as s:
return s.post(*args, **kwargs)
return s.post(headers=_headers, *args, **kwargs)