Skip to content

Commit

Permalink
Use a custom User-Agent when validating
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed May 24, 2022
1 parent 4155617 commit 37f2d50
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions optimade/validator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import requests
from pydantic import Field, ValidationError

from optimade import __version__
from optimade.models.optimade_json import Success
from optimade.models import (
ResponseMeta,
Expand All @@ -40,6 +41,7 @@
# (see https://docs.python-requests.org/en/latest/user/advanced/#timeouts)
DEFAULT_CONN_TIMEOUT = 3.05
DEFAULT_READ_TIMEOUT = 60
DEFAULT_USER_AGENT_STRING = f"optimade-python-tools validator/{__version__}"


class ResponseError(Exception):
Expand Down Expand Up @@ -199,6 +201,8 @@ def __init__(
self.response = None
self.max_retries = max_retries
self.headers = headers or {}
if "User-Agent" not in self.headers:
self.headers["User-Agent"] = DEFAULT_USER_AGENT_STRING
self.timeout = timeout or DEFAULT_CONN_TIMEOUT
self.read_timeout = read_timeout or DEFAULT_READ_TIMEOUT

Expand Down

0 comments on commit 37f2d50

Please sign in to comment.