Skip to content

Commit

Permalink
Allow passing session with custom user agent.
Browse files Browse the repository at this point in the history
Closes #446
  • Loading branch information
facetoe committed Sep 6, 2020
1 parent 178b7a4 commit 2286ad5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions zenpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ def _init_session(self, email, token, oath_token, password, session):
else:
raise ZenpyException("Invalid arguments to _init_session()!")

headers = {"User-Agent": "Zenpy/{}".format(__version__)}
session.headers.update(headers)
# If a session with a custom user agent has been passed, don't clobber it
if "User-Agent" in session.headers:
user_agent = session.headers.get("User-Agent")
if user_agent == requests.utils.default_user_agent():
user_agent = "Zenpy/{}".format(__version__)
session.headers.update({"User-Agent": user_agent})
return session

def get_cache_names(self):
Expand Down

0 comments on commit 2286ad5

Please sign in to comment.