-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix error decoding of string body #31265
Conversation
If error_body is a string, calling iter() on it will result in: AttributeError: 'str' object has no attribute 'iter'. Use the body as message instead.
Thank you for your contribution @kldtz! We will review the pull request and get back to you soon. |
Thanks so much @kldtz! |
Hi @annatisch, sure: client = TableClient(
# wrong endpoint that responds with HTML
endpoint="https://<storage>.z6.web.core.windows.net/",
credential=DefaultAzureCredential(),
table_name="table-name"
)
client.submit_transaction([
(
"upsert",
{
"PartitionKey": "test-partition",
"RowKey": "test-key",
"name": "test-name",
},
)
]) I just saw that in other places |
Hi @kldtz , I got client = TableClient(
# wrong endpoint that responds with HTML
endpoint="https://<tables_storage_account_name>.z6.web.core.windows.net/",
credential=DefaultAzureCredential(),
table_name="table-name"
)
with pytest.raises(ServiceRequestError) as ex:
client.submit_transaction([
(
"upsert",
{
"PartitionKey": "test-partition",
"RowKey": "test-key",
"name": "test-name",
},
)
])
assert "Failed to establish a new connection" in str(ex.value) Do you know if I missed anything? |
Hi @YalinLi0312 , you can try this snippet, where I monkey-patched the from functools import partial
from typing import Any
from azure.core.pipeline import HTTPRequestType, PipelineResponse, HTTPResponseType
from azure.core.pipeline.transport._requests_basic import RequestsTransportResponse
from azure.data.tables import TableClient
from azure.identity import DefaultAzureCredential
from requests import Response
def patch_run(self, request: HTTPRequestType, **kwargs: Any) -> PipelineResponse[HTTPRequestType, HTTPResponseType]:
response = Response()
response.status_code = 405
response._content = b"<!DOCTYPE html><html><head><title>UnsupportedHttpVerb</title></head><body><h1>The resource doesn't support specified Http Verb.</h1><p><ul><li>HttpStatusCode: 405</li><li>ErrorCode: UnsupportedHttpVerb</li><li>RequestId : 98adf858-a01e-0071-2580-bfe811000000</li><li>TimeStamp : 2023-07-26T05:19:26.9825582Z</li></ul></p></body></html>"
response.url = 'https://<storage>.z6.web.core.windows.net/$batch'
response.headers = {
"x-ms-error-code": "UnsupportedHttpVerb",
"content-type": "text/html"
}
return PipelineResponse(
http_request=None,
http_response=RequestsTransportResponse(
requests_response=response,
request=None,
),
context=None,
)
if __name__ == '__main__':
client = TableClient(
endpoint="https://<storage>.z6.web.core.windows.net/",
credential=DefaultAzureCredential(),
table_name="syncenabled"
)
client._client._client._pipeline.run = partial(patch_run, client)
client.submit_transaction([
(
"upsert",
{
"PartitionKey": "test-partition",
"RowKey": "test-key",
"name": "test-name",
},
)
]) If the content type is |
Thank you, I'll try on it! |
Hi @kldtz , I did reproduce the error with the sample you provided. Can you assign me the permission to edit on your branch? I want to add some tests. |
@YalinLi0312 As far as I can see, you already have edit rights. |
It failed due to lacking permission when I tried. Can you assign me the permission? Or do you mind me fixing it in another PR? |
"Allow edits by maintainers" is checked. Not sure what else I can do. You can fix it in another PR. |
@microsoft-github-policy-service agree |
Co-authored-by: Anna Tisch <[email protected]>
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.
Thanks @kldtz, @YalinLi0312!
Co-authored-by: Anna Tisch <[email protected]>
Hi @kldtz - we'll prepare a release with this fix on 9/12/2023, please give it a try and welcome to any feedback! |
If
error_body
is a string (which may happen), calling iter() on it will result in:AttributeError: 'str' object has no attribute 'iter'
. Use the body as message instead.This error appeared when I configured a wrong endpoint that returned an HTML error response. The AttributeError was hiding the actual error, which made debugging the problem harder.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines