AttributeError: 'BlobMedia' object has no attribute 'status'

I am making an HTTP request from client code and I want to ensure the status of the response is a successful one. The response from my API returns a 204 upon success with no response body.

When I try to access the status code from the anvil response, I receive this error:
AttributeError: 'BlobMedia' object has no attribute 'status'

The code I am using to try to access the status code is:

resp = anvil.http.request(
  url=f"{APP_ENGINE_URL}/donations/{event_args['row']['id']}",
  method="DELETE"
)
if resp.status == 204:
  self.all_tabulator.delete_row(event_args['row']['id'])

Welcome back!

You might want to see the example here: HTTP error codes

That is where I started. I want to test for a success code, not catch an error code

Hmm… I don’t have any HTTP code. What happens when you call dir on the response, e.g.,

dir(resp)

?

I get this:

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__repr__', '__setattr__', '__str__', 'get_bytes', 'get_content_type', 'get_length', 'get_name', 'get_url']

Darn. You can see members there for Python infrastructure (e.g., __class__), and response-specific members (e.g., get_bytes), but nothing in there that looks helpful for your question.

Well, it was worth a shot. dir can be applied to any Python object, to learn more about it.

The try block is the closest thing I can think of. If the except clause doesn’t fire, then (by definition?) it’s a success. But it might not be the specific success you’re looking for.

If that’s not close enough, then it might be time to file a Feature Request.

Linked docs
https://anvil.works/docs/http-apis/making-http-requests

By default you get a Media object as the return value from an http response unless you set json=True.
(Which I think might be what you want here)

A linked post that might be helpful

Got it, that works for me!