Skip to content
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

Properly handle non-200 responses on multi-url requests #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dougkeen
Copy link

Currently, multi-url requests throw a ValueError when constructing the return list if the api requests returns anything other than a 200 response. The error happens specifically in this code:

return map(lambda url, data: Url(data, method, url),
                        url_or_urls, data)

When the status code isn't 200 (and it's a multi-url request), the data value is assigned to a dictionary (as opposed the list/json array you'd expect from a 200 response). When passed to map(lambda url, data: Url(data, method, url), url_or_urls, data), map iterates through data and url_or_urls in parallel. Under successful 200 responses, data and url_or_urls are lists of equal length. In any other case, data is a dictionary, so map iterates through the keys of the dictionary. This causes exceptions because the data arg passed to the lambda func is now a string, not a dict.

This fix works by simply copying the error data len(url_or_urls) times in a list, mimicking the list format expected in the downstream map function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant