Skip to content

Commit d79af52

Browse files
Fix bug that caused User-Agent header to be omitted from HTTP requests
1 parent f44070d commit d79af52

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
## [Unreleased]
9+
### Added
10+
### Changed
11+
### Deprecated
12+
### Removed
13+
### Fixed
14+
* Fix bug that caused User-Agent header to be omitted from HTTP requests.
15+
### Security
16+
17+
818
## [1.2.0] - 2021-10-07
919
### Added
1020
* Add `Translator.get_glossary_languages()` to query language pairs supported for glossaries.
@@ -85,7 +95,8 @@ Version increased to avoid conflicts with old packages on PyPI.
8595
Initial version.
8696

8797

88-
[1.2.0]: https://github.com/DeepLcom/deepl-python/compare/v1.1.3...v1.2.0
98+
[Unreleased]: https://github.com/DeepLcom/deepl-python/compare/v1.2.0...HEAD
99+
[1.2.0]: https://github.com/DeepLcom/deepl-python/compare/v1.1.3...v1.2.0
89100
[1.1.3]: https://github.com/DeepLcom/deepl-python/compare/v1.1.2...v1.1.3
90101
[1.1.2]: https://github.com/DeepLcom/deepl-python/compare/v1.1.1...v1.1.2
91102
[1.1.1]: https://github.com/DeepLcom/deepl-python/compare/v1.1.0...v1.1.1

deepl/http_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def request_with_backoff(
7171
method: str,
7272
url: str,
7373
data: Optional[dict],
74+
headers: dict,
7475
stream: bool = False,
7576
**kwargs,
7677
) -> Tuple[int, Union[str, requests.Response]]:
@@ -80,8 +81,9 @@ def request_with_backoff(
8081
backoff = _BackoffTimer()
8182

8283
try:
84+
headers.setdefault("User-Agent", user_agent)
8385
request = requests.Request(
84-
method, url, data=data, **kwargs
86+
method, url, data=data, headers=headers, **kwargs
8587
).prepare()
8688
except Exception as e:
8789
raise DeepLException(
@@ -123,6 +125,7 @@ def request(
123125
method: str,
124126
url: str,
125127
data: Optional[dict],
128+
headers: dict,
126129
stream: bool = False,
127130
**kwargs,
128131
) -> Tuple[int, Union[str, requests.Response]]:
@@ -134,8 +137,9 @@ def request(
134137
If no response is received will raise ConnectionException."""
135138

136139
try:
140+
headers.setdefault("User-Agent", user_agent)
137141
request = requests.Request(
138-
method, url, data=data, **kwargs
142+
method, url, data=data, headers=headers, **kwargs
139143
).prepare()
140144
except Exception as e:
141145
raise DeepLException(

0 commit comments

Comments
 (0)