Skip to content

Commit 4d4ad65

Browse files
makew0rldpeeter123
authored andcommitted
Use static user agent (#24)
* Use static user agent * Remove fake_useragent import
1 parent 61bfed4 commit 4d4ad65

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

digikey/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
logger = logging.getLogger(__name__)
99

10+
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0'
11+
1012

1113
def setup_logger(logger_ref):
1214
logger_ref.setLevel(logging.DEBUG)

digikey/oauth/oauth2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import requests
1414
from certauth.certauth import CertificateAuthority
15-
from fake_useragent import UserAgent
1615

16+
from digikey import USER_AGENT
1717
from digikey.exceptions import DigikeyOauthException
1818

1919
CA_CERT = 'digikey-api.pem'
@@ -161,7 +161,7 @@ def __build_authorization_url(self) -> str:
161161
return url
162162

163163
def __exchange_for_token(self, code):
164-
headers = {'user-agent': f'{UserAgent().firefox}',
164+
headers = {'user-agent': USER_AGENT,
165165
'Content-type': 'application/x-www-form-urlencoded'
166166
}
167167
post_data = {'grant_type': 'authorization_code',
@@ -189,7 +189,7 @@ def __exchange_for_token(self, code):
189189
return token_json
190190

191191
def __refresh_token(self, refresh_token: str):
192-
headers = {'user-agent': f'{UserAgent().firefox}',
192+
headers = {'user-agent': USER_AGENT,
193193
'Content-type': 'application/x-www-form-urlencoded'
194194
}
195195
post_data = {'grant_type': 'refresh_token',

digikey/v2/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from pathlib import Path
66

77
import requests
8-
from fake_useragent import UserAgent
98

9+
from digikey import USER_AGENT
1010
from digikey.v2 import models
1111
from digikey.decorators import retry
1212
from digikey.exceptions import DigikeyError
@@ -63,7 +63,7 @@ def _request(self,
6363
path: str,
6464
data: t.Dict[str, t.Any]=None
6565
) -> t.Any:
66-
headers = {'user-agent': f'{UserAgent().firefox}',
66+
headers = {'user-agent': USER_AGENT,
6767
'x-ibm-client-id': self._id,
6868
'authorization': self.oauth2.get_authorization()}
6969

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
inflection
22
certauth
3-
fake-useragent
43
requests
54
retrying
65
schematics

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
install_requires=[
2727
'requests>=2.22.0',
2828
'retrying>=1.3.3',
29-
'fake-useragent>=0.1.11',
3029
'schematics>=2.1.0',
3130
'inflection>=0.3.1',
3231
'certauth>=1.3.0',
3332
'urllib3>=1.25.3'
3433
],
3534
tests_requires=['pytest>=5.1.2'],
36-
)
35+
)

0 commit comments

Comments
 (0)