Merge lp:~mwhudson/ssh-import-id/lp-1770305 into lp:ssh-import-id

Proposed by Michael Hudson-Doyle
Status: Merged
Merge reported by: Scott Moser
Merged at revision: not available
Proposed branch: lp:~mwhudson/ssh-import-id/lp-1770305
Merge into: lp:ssh-import-id
Diff against target: 21 lines (+9/-2)
1 file modified
ssh_import_id/__init__.py (+9/-2)
To merge this branch: bzr merge lp:~mwhudson/ssh-import-id/lp-1770305
Reviewer Review Type Date Requested Status
ssh-import-id Pending
Review via email: mp+345334@code.launchpad.net

Description of the change

check status code of response when fetching ssh keys from launchpad

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

+1, hoping to move to git.

Revision history for this message
Scott Moser (smoser) wrote :

merged this in git.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ssh_import_id/__init__.py'
2--- ssh_import_id/__init__.py 2017-07-11 20:51:44 +0000
3+++ ssh_import_id/__init__.py 2018-05-10 03:37:59 +0000
4@@ -281,8 +281,15 @@
5 if url is None:
6 url = "https://launchpad.net/~%s/+sshkeys" % (quote_plus(lpid))
7 headers = {'User-Agent': user_agent(useragent)}
8- text = requests.get(url, verify=True, headers=headers).text
9- keys = str(text)
10+ response = requests.get(url, verify=True, headers=headers)
11+ if response.status_code != 200:
12+ if response.status_code == 404:
13+ print('Launchpad user "%s" not found'%lpid)
14+ sys.exit(1)
15+ else:
16+ print('Requesting ssh keys for user "%s" failed with unexpected code %s'%(lpid, response.status_code))
17+ sys.exit(1)
18+ keys = str(response.text)
19 except (Exception,):
20 e = sys.exc_info()[1]
21 sys.stderr.write("ERROR: %s\n" % (str(e)))

Subscribers

People subscribed via source and target branches