-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hotfixing urllib2 + bwb API #2779
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import web | ||
import urllib2 | ||
import simplejson | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm suspicious of the If the data is actually returned as XML, why are we "parsing" it with regexs instead of an XML parser? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mekarpeles I've been finding The The two imports on this file and refactor should be removed. |
||
import requests | ||
from amazon.api import SearchException | ||
from infogami import config | ||
from infogami.utils.view import public | ||
|
@@ -13,7 +14,7 @@ | |
from openlibrary import accounts | ||
|
||
|
||
BETTERWORLDBOOKS_API_URL = 'http://products.betterworldbooks.com/service.aspx?ItemId=' | ||
BETTERWORLDBOOKS_API_URL = 'https://products.betterworldbooks.com/service.aspx?ItemId=' | ||
AMAZON_FULL_DATE_RE = re.compile('\d{4}-\d\d-\d\d') | ||
ISBD_UNIT_PUNCT = ' : ' # ISBD cataloging title-unit separator punctuation | ||
|
||
|
@@ -291,10 +292,8 @@ def _get_betterworldbooks_metadata(isbn): | |
|
||
url = BETTERWORLDBOOKS_API_URL + isbn | ||
try: | ||
req = urllib2.Request(url) | ||
f = urllib2.urlopen(req) | ||
response = f.read() | ||
f.close() | ||
r = requests.get(url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that Requests doesn't throw an exception like urllib2 does, so it needs explicit status checking. I've taken a crack at repairing it in #2894, but this was flagged as an issue over 3 weeks ago, so I would have hoped to not have to take it on myself (as part of the Python 3 work). |
||
response = r.content | ||
product_url = re.findall("<DetailURLPage>\$(.+)</DetailURLPage>", response) | ||
new_qty = re.findall("<TotalNew>([0-9]+)</TotalNew>", response) | ||
new_price = re.findall("<LowestNewPrice>\$([0-9.]+)</LowestNewPrice>", response) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed and the exception handling for the referenced
urllib2.HTTPError
reviewed and updated as necessary.