adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

update requests_wifi_advanced to 9.0 with Connection Manager #178

Closed DJDevon3 closed 2 months ago

DJDevon3 commented 3 months ago

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:

Connecting to WiFi...
Signal Strength: -59
✅ Wifi!
 | Fetching JSON: https://httpbin.org/get
 | ✅ Response Custom User-Agent Header: blinka/1.0.0
 | ✅ Response HTTP Status Code: 200
 | ✂️ Disconnected from https://httpbin.org/get
Finished!

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.

DJDevon3 commented 3 months ago

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.

Connecting to WiFi...
Signal Strength: -63
✅ Wifi!
 | GET JSON: https://httpbin.org/get
 | User-Agent: blinka/1.0.0
 | ✅ Status Test: 200 - OK
 | ✂️ Disconnected from https://httpbin.org/get
 | 
 | Status Code Test: https://httpbin.org/status/
 | ✅ Status Test: 100 - Continue
 | ✅ Status Test: 101 - Switching Protocols
 | ✅ Status Test: 102 - Processing
 | ✅ Status Test: 103 - Early Hints
 | ✅ Status Test: 200 - OK
 | ✅ Status Test: 201 - Created
 | ✅ 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: 200 - OK
 | ❌ Status Test: 306 - Unused
 | ✅ Status Test: 200 - OK
 | ❌ Status Test: 308 - Permanent Redirect
 | ❌ 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: 431 - Request Header Fields Too Large
 | ❌ 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!
DJDevon3 commented 2 months ago

Sounds good will do.

DJDevon3 commented 2 months ago

Modified closer to original. Since it's supposed to be called Advanced I put a few more http headers. in there.

Connecting to WiFi...
Signal Strength: -53
✅ Wifi!
 | Fetching JSON: https://httpbin.org/get
 | 🆗 Status Code: 200
 |  | Custom User-Agent Header: blinka/1.0.0
 |  | Content-Type: application/json
 |  | Response Timestamp: Thu, 11 Apr 2024 13:16:34 GMT
 | ✂️ Disconnected from https://httpbin.org/get

Split Status Code into its own example also included in this commit.

DJDevon3 commented 2 months ago

Current output example


Connecting to WiFi...
Signal Strength: -60
✅ Wifi!
 | Fetching JSON data from https://httpbin.org/get...
 | 🆗 Status Code: 200
 |  | Custom User-Agent Header: blinka/1.0.0
 |  | Content-Type: application/json
 |  | Response Timestamp: Mon, 15 Apr 2024 16:55:12 GMT
DJDevon3 commented 2 months ago

changed to

Connecting to WiFi...
Signal Strength: -58
✅ Wifi!
 | Fetching URL https://httpbin.org/get
 | 🆗 Status Code: 200
 |  | Custom User-Agent Header: blinka/1.0.0
 |  | Content-Type: application/json
 |  | Response Timestamp: Mon, 15 Apr 2024 17:20:13 GMT
DJDevon3 commented 2 months ago

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?

FoamyGuy commented 2 months ago

@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.

DJDevon3 commented 2 months ago

@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.