-
Notifications
You must be signed in to change notification settings - Fork 37
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
update requests_wifi_advanced to 9.0 with Connection Manager #178
Conversation
httpbin has pages to test all HTTP status codes
Added an HTTP status error code tester which works with httpbin.org I expanded it to test every code. I think this is more worthy of the filename as an advanced test. A great example that teaches how to set a custom user-agent and catch error codes with API's to do things with them.
|
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.
I think we can remove the pylint disable commeent.
cleaning up discrepancy between my local pylint and adafruit actions.
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.
I think the complete list of status code checks that were added are a little excessive currently.
I would recommend one of:
- leave this example as just the single request and make a new "status code list" example for this loop that checks all of these different ones
- maybe update this example to have a small set of 4-6 or so most commonly used status codes only, and remove the rest, or move them into a separate example.
Sounds good will do. |
Modified closer to original. Since it's supposed to be called Advanced I put a few more http headers. in there.
Split Status Code into its own example also included in this commit. |
added additional http headers, removed most status codes for separate example
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.
My results from testing the new status code example seem to show several repititions of some of the status codes instead of printing output for each of them once like the loop seems like it should make it do.
| ✅ Status Test: 202 - Accepted
| ✅ Status Test: 203 - Non-Authoritative Information
| ✅ Status Test: 204 - No Content
| ✅ Status Test: 205 - Reset Content
| ✅ Status Test: 206 - Partial Content
| ✅ Status Test: 207 - Multi-Status
| ✅ Status Test: 208 - Already Reported
| ✅ Status Test: 226 - IM Used
| ❌ Status Test: 300 - Multiple Choices
| ✅ Status Test: 200 - OK
| ✅ Status Test: 200 - OK
| ✅ Status Test: 200 - OK
| ❌ Status Test: 304 - Not Modified
| ❌ Status Test: 502 - Bad Gateway
| ❌ Status Test: 306 - Unused
| ✅ Status Test: 200 - OK
| ❌ Status Test: 502 - Bad Gateway
| ❌ Status Test: 400 - Bad Request
| ❌ Status Test: 401 - Unauthorized
| ❌ Status Test: 402 - Payment Required
| ❌ Status Test: 403 - Forbidden
| ❌ Status Test: 404 - Not Found
| ❌ Status Test: 405 - Method Not Allowed
| ❌ Status Test: 406 - Not Acceptable
| ❌ Status Test: 407 - Proxy Authentication Required
| ❌ Status Test: 408 - Request Timeout
| ❌ Status Test: 409 - Conflict
| ❌ Status Test: 410 - Gone
| ❌ Status Test: 411 - Length Required
| ❌ Status Test: 412 - Precondition Failed
| ❌ Status Test: 413 - Payload Too Large
| ❌ Status Test: 414 - URI Too Long
| ❌ Status Test: 415 - Unsupported Media Type
| ❌ Status Test: 416 - Range Not Satisfiable
| ❌ Status Test: 417 - Expectation Failed
| ❌ Status Test: 418 - I'm a teapot
| ❌ Status Test: 421 - Misdirected Request
| ❌ Status Test: 422 - Unprocessable Entity
| ❌ Status Test: 423 - Locked
| ❌ Status Test: 424 - Failed Dependency
| ❌ Status Test: 425 - Too Early
| ❌ Status Test: 426 - Upgrade Required
| ❌ Status Test: 428 - Precondition Required
| ❌ Status Test: 429 - Too Many Requests
| ❌ Status Test: 502 - Bad Gateway
| ❌ Status Test: 451 - Unavailable For Legal Reasons
| ❌ Status Test: 500 - Internal Server Error
| ❌ Status Test: 501 - Not Implemented
| ❌ Status Test: 502 - Bad Gateway
| ❌ Status Test: 503 - Service Unavailable
| ❌ Status Test: 504 - Gateway Timeout
| ❌ Status Test: 505 - HTTP Version Not Supported
| ❌ Status Test: 506 - Variant Also Negotiates
| ❌ Status Test: 507 - Insufficient Storage
| ❌ Status Test: 508 - Loop Detected
| ❌ Status Test: 510 - Not Extended
| ❌ Status Test: 511 - Network Authentication Required
| ✂️ Disconnected from https://httpbin.org/get
Finished!
200
is repeated 5 times, one of which is in it's proper place in the sequence.
502
is repeated 4 times, one of which is in it's proper place in the sequeence.
I'm guessing that the server replying to these requests can't handle a few of the types we've attempted and returned 502 in those cases.
And for some of the redirects it looks like there may be client code in requests library that is automatically following the redirect which is ultimately resulting in 200 responses instead of the expected 30x ones.
I'm in favor of removing any of the status codes that are unsupported by the server and return 502 instead of the expected result.
For the 300s that end up following the redirect I think there is value in keeping them, but either a code comment or something in the print out should maybe try to clarify why they are different from expected status codes. Maybe they could specify what status was expected and what status was ultimately found? like this:
| ❌ Status Test: expected: 300 actual: 300 - Multiple Choices
| ✅ Status Test: expected: 301 actual: 200 - OK
| ✅ Status Test: expected: 302 actual: 200 - OK
| ✅ Status Test: expected: 303 actual: 200 - OK
| ❌ Status Test: expected: 304 actual: 304 - Not Modified
| ✅ Status Test: expected: 305 actual: 200 - OK
| ❌ Status Test: expected: 306 actual: 306 - Unused
| ✅ Status Test: expected: 307 actual: 200 - OK
STATUS_DESCRIPTION = http_status_codes.get(STATUS_CODE, "Unknown Status Code") | ||
print_http_status(STATUS_CODE, STATUS_DESCRIPTION) | ||
response.close() | ||
print(f" | ✂️ Disconnected from {JSON_GET_URL}") |
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.
Now that this is moved into it's own example that illustrates the whole list of status codes I think I'm infavor of getting rid of this single request that happens up here before the list. I think we could get rid of the JSON_GET_URL
entirely from this example and make it just the STATUS_TEST url.
This is more like the original advanced example.
Current output example
|
changed to
|
The variable is actually an http header status test so keeping it as url instead of json_url for that one is good.
looks like Justin fixed these in #188 so I basically just repeated the work before seeing his commit. Not sure what to do here. Should I close this PR? |
@DJDevon3 I think it can stay open. This PR contains the new status code example, and #188 contains updates to many other (perhaps all) of the examples. So there is a little bit of crossover in the one advanced example, but there is also plenty of work that is separate and only in it's own respective PR on both sides. |
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.
There are still a few unresolved changes that I think would be good to have before merging this.
- remove the
JSON_GET_URL
and the single request that uses it that comes before the loop with all of the status requests. I think it's best to make the status example just do the status loop and not the single request before it, that looks to be leftover from when this was copied from advanced. - Add the expected status codes to the printed output so that its' easy to tell which codes are actually returning different from the expected values (mostly the 300s level redirects, but a few of the others them returned duplicates of 502 for me when I tested the other day as well)
I can make those changes and commit them to this branch if you'd like, let me know.
@FoamyGuy Yes please by all mean do. I'm a bit PR'd out at the moment. The ISFL31 typing PR took a lot of wind out of my sail. I would like to work on some 3D design projects and get my mind off code for a while. |
# Conflicts: # examples/wifi/requests_wifi_advanced.py
…context inside status codes loop. Add expected code to print out.
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.
Looks good to me. I like the changes to the status codes example, very nice.
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.
Latest commits incorporate all of the requested changes.
Thanks for taking a look @DJDevon3.
Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 3.2.8 from 3.2.6: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#182 from DJDevon3/DJDevon3-QueueTimesAPI > Merge pull request adafruit/Adafruit_CircuitPython_Requests#178 from DJDevon3/DJDevon3-WifiAdvanced Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Updating requests_wifi_advanced to 9.0 with Connection Manager
This example is only for setting up a custom user-agent and using response status codes.
Added
Serial output example:
I think this example could be expanded upon to include the most common status codes and return the appropriate error message with them. I might work on this more.