Skip to content

Commit 328835c

Browse files
authored
Merge pull request #11679 from jimchamp/copydocs-auth
Fix `copydocs.py` authentication errors
2 parents f1f2bed + b1251c1 commit 328835c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

openlibrary/api.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ def __init__(self, base_url="https://openlibrary.org"):
4242
self.base_url = base_url.rstrip('/') if base_url else "https://openlibrary.org"
4343
self.cookie = None
4444

45-
def _request(self, path, method='GET', data=None, headers=None, params=None):
45+
def _request(
46+
self,
47+
path,
48+
method='GET',
49+
data=None,
50+
headers=None,
51+
params=None,
52+
allow_redirects=True,
53+
):
4654
logger.info("%s %s", method, path)
4755
url = self.base_url + path
4856
headers = headers or {}
@@ -52,7 +60,12 @@ def _request(self, path, method='GET', data=None, headers=None, params=None):
5260

5361
try:
5462
response = requests.request(
55-
method, url, data=data, headers=headers, params=params
63+
method,
64+
url,
65+
data=data,
66+
headers=headers,
67+
params=params,
68+
allow_redirects=allow_redirects,
5669
)
5770
response.raise_for_status()
5871
return response
@@ -95,11 +108,10 @@ def autologin(self, section=None):
95108

96109
def login(self, username, password):
97110
"""Login to Open Library with given credentials."""
98-
headers = {'Content-Type': 'application/json'}
99111
try:
100-
data = json.dumps({"username": username, "password": password})
112+
params = {"username": username, "password": password}
101113
response = self._request(
102-
'/account/login', method='POST', data=data, headers=headers
114+
'/account/login', method='POST', params=params, allow_redirects=False
103115
)
104116
except OLError as e:
105117
response = e

scripts/copydocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def main(
367367
if section in read_lines(os.path.expanduser("~/.olrc")):
368368
dest_ol.autologin()
369369
else:
370-
dest_ol.login("admin", "admin123")
370+
dest_ol.login("openlibrary@example.com", "admin123")
371371

372372
for list_key in lists or []:
373373
copy_list(src_ol, dest_ol, list_key, comment=comment)

0 commit comments

Comments
 (0)