Skip to content

Conversation

davispuh
Copy link

When server doesn't return anything

  File "urequests.py", line 100, in request
  File "urequests.py", line 84, in request
IndexError: list index out of range

@andrewleech andrewleech mentioned this pull request Jun 20, 2022
@andrewleech
Copy link
Contributor

Hello I know this was a long time ago, but I'm trying to collate some urequests updates now. Do you remember, is there any valid case where this should happen?
I see your change takes affect if there isn't even a status code in the response which appears to be completely invalid http, a quick test shows that cpython requests library gives a long list of exception messages in this case, I don't think we should simply return an empty reponse instead.
I've added a new commit to my working branch inspired by yours here, however I raise a ValueError with an error message instead. Does this sound appropriate to you?

@davispuh
Copy link
Author

It's been way too long so I really don't remember :D but I think I encountered some API that sometimes had issues so it would immediately close connection and you wouldn't get any data. Because I don't even remember what project it was this seems to not matter anymore and I think your approach should be fine.

Generally even with broken HTTP servers sometimes you still might want to get whatever they returned.

@andrewleech
Copy link
Contributor

Thanks for the reply, yep that sounds reasonable. I updated my commit slightly to still raise the exception, but then also print out whatever was received as well.

@andrewleech
Copy link
Contributor

dbd8fff was merged as part of #500 which raises a ValueError as suggested above with a message that should make it clear the error that's occurred. Thanks again!

@andrewleech andrewleech closed this Jul 3, 2022
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.

2 participants