Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,31 @@ def order_results(response, combined):


def prepare_result(func):
def _get_error_code_and_message(error):
if hasattr(error.error, 'innererror') and error.error.innererror:
return error.error.innererror.code, error.error.innererror.message
Comment thread
iscai-msft marked this conversation as resolved.
return error.error.code, error.error.message

def _deal_with_too_many_documents(response, obj):
# special case for now if there are too many documents in the request
# they may change id to empty string, but currently it is "All"
too_many_documents_errors = [
error for error in obj.errors
if error.id == "All" and _get_error_code_and_message(error)[0] == "InvalidDocumentBatch"
Comment thread
iscai-msft marked this conversation as resolved.
Outdated
]
if too_many_documents_errors:
too_many_documents_error = too_many_documents_errors[0]
response.status_code = 400
response.reason = "Bad Request"
code, message = _get_error_code_and_message(too_many_documents_error)
raise HttpResponseError(
message="({}) {}".format(code, message),
response=response
)

def wrapper(response, obj, response_headers): # pylint: disable=unused-argument
if obj.errors:
_deal_with_too_many_documents(response.http_response, obj)
combined = obj.documents + obj.errors
results = order_results(response, combined)
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/sentiment?showStats=false
response:
body:
string: '{"error":{"code":"401","message": "Access denied due to invalid subscription
key or wrong API endpoint. Make sure to provide a valid key for an active
subscription and use a correct regional API endpoint for your resource."}}'
headers:
apim-request-id:
- bf46ec9a-cf1f-41ac-bd51-d054d070533d
content-length:
- '225'
content-type:
- application/json
date:
- Fri, 01 May 2020 16:08:26 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
www-authenticate:
- AzureApiManagementKey realm="https://westus2.ppe.cognitiveservices.azure.com/text/analytics",name="Ocp-Apim-Subscription-Key",type="header"
x-content-type-options:
- nosniff
status:
code: 401
message: Access Denied
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/sentiment?showStats=false
response:
body:
string: '{"error":{"code":"401","message": "Access denied due to invalid subscription
key or wrong API endpoint. Make sure to provide a valid key for an active
subscription and use a correct regional API endpoint for your resource."}}'
headers:
apim-request-id: 68c140f8-c5a1-4715-b5ce-48264492a66c
content-length: '225'
content-type: application/json
date: Fri, 01 May 2020 16:08:27 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
www-authenticate: AzureApiManagementKey realm="https://westus2.ppe.cognitiveservices.azure.com/text/analytics",name="Ocp-Apim-Subscription-Key",type="header"
x-content-type-options: nosniff
status:
code: 401
message: Access Denied
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/sentiment?showStats=false
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "countryHint": "US"}, {"id":
"1", "text": "Two", "countryHint": "US"}, {"id": "2", "text": "Three", "countryHint":
"US"}, {"id": "3", "text": "Four", "countryHint": "US"}, {"id": "4", "text":
"Five", "countryHint": "US"}, {"id": "5", "text": "Six", "countryHint": "US"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '313'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/languages?showStats=false
response:
body:
string: '{"error":{"code":"401","message": "Access denied due to invalid subscription
key or wrong API endpoint. Make sure to provide a valid key for an active
subscription and use a correct regional API endpoint for your resource."}}'
headers:
apim-request-id:
- fa964233-6518-4347-ac78-2e5496fff910
content-length:
- '225'
content-type:
- application/json
date:
- Fri, 01 May 2020 16:08:28 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
www-authenticate:
- AzureApiManagementKey realm="https://westus2.ppe.cognitiveservices.azure.com/text/analytics",name="Ocp-Apim-Subscription-Key",type="header"
x-content-type-options:
- nosniff
status:
code: 401
message: Access Denied
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "countryHint": "US"}, {"id":
"1", "text": "Two", "countryHint": "US"}, {"id": "2", "text": "Three", "countryHint":
"US"}, {"id": "3", "text": "Four", "countryHint": "US"}, {"id": "4", "text":
"Five", "countryHint": "US"}, {"id": "5", "text": "Six", "countryHint": "US"}]}'
headers:
Accept:
- application/json
Content-Length:
- '313'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/languages?showStats=false
response:
body:
string: '{"error":{"code":"401","message": "Access denied due to invalid subscription
key or wrong API endpoint. Make sure to provide a valid key for an active
subscription and use a correct regional API endpoint for your resource."}}'
headers:
apim-request-id: 5d1d9707-ed31-43a4-b497-c986c879332b
content-length: '225'
content-type: application/json
date: Fri, 01 May 2020 16:08:30 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
www-authenticate: AzureApiManagementKey realm="https://westus2.ppe.cognitiveservices.azure.com/text/analytics",name="Ocp-Apim-Subscription-Key",type="header"
x-content-type-options: nosniff
status:
code: 401
message: Access Denied
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/languages?showStats=false
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/keyPhrases?showStats=false
response:
body:
string: '{"error":{"code":"401","message": "Access denied due to invalid subscription
key or wrong API endpoint. Make sure to provide a valid key for an active
subscription and use a correct regional API endpoint for your resource."}}'
headers:
apim-request-id:
- ca6f7eac-c982-4ec8-9173-32d8288d9ddd
content-length:
- '225'
content-type:
- application/json
date:
- Fri, 01 May 2020 16:08:32 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
www-authenticate:
- AzureApiManagementKey realm="https://westus2.ppe.cognitiveservices.azure.com/text/analytics",name="Ocp-Apim-Subscription-Key",type="header"
x-content-type-options:
- nosniff
status:
code: 401
message: Access Denied
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/keyPhrases?showStats=false
response:
body:
string: '{"error":{"code":"401","message": "Access denied due to invalid subscription
key or wrong API endpoint. Make sure to provide a valid key for an active
subscription and use a correct regional API endpoint for your resource."}}'
headers:
apim-request-id: 1eb41936-0c49-4c56-a8b4-4daf46201094
content-length: '225'
content-type: application/json
date: Fri, 01 May 2020 16:08:33 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
www-authenticate: AzureApiManagementKey realm="https://westus2.ppe.cognitiveservices.azure.com/text/analytics",name="Ocp-Apim-Subscription-Key",type="header"
x-content-type-options: nosniff
status:
code: 401
message: Access Denied
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/keyPhrases?showStats=false
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/recognition/general?showStats=false
response:
body:
string: '{"documents":[{"id":"0","entities":[{"text":"One","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"1","entities":[{"text":"Two","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"2","entities":[{"text":"Three","category":"Quantity","subcategory":"Number","offset":0,"length":5,"confidenceScore":0.8}],"warnings":[]},{"id":"3","entities":[{"text":"Four","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"4","entities":[{"text":"Five","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"5","entities":[{"text":"Six","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]}],"errors":[{"id":"All","error":{"code":"InvalidArgument","message":"The
request contains a warning.","innererror":{"code":"InvalidDocumentBatch","message":"The
number of documents in the request have exceeded the data limitations. See
https://aka.ms/text-analytics-data-limits for additional information"}}}],"modelVersion":"2020-04-01"}'
headers:
apim-request-id:
- 3f938077-141a-48c0-a8dc-45158ca76ca6
content-type:
- application/json; charset=utf-8
csp-billing-usage:
- CognitiveServices.TextAnalytics.BatchScoring=6
date:
- Thu, 30 Apr 2020 18:38:28 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '87'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: '{"documents": [{"id": "0", "text": "One", "language": "en"}, {"id": "1",
"text": "Two", "language": "en"}, {"id": "2", "text": "Three", "language": "en"},
{"id": "3", "text": "Four", "language": "en"}, {"id": "4", "text": "Five", "language":
"en"}, {"id": "5", "text": "Six", "language": "en"}]}'
headers:
Accept:
- application/json
Content-Length:
- '295'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/recognition/general?showStats=false
response:
body:
string: '{"documents":[{"id":"0","entities":[{"text":"One","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"1","entities":[{"text":"Two","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]},{"id":"2","entities":[{"text":"Three","category":"Quantity","subcategory":"Number","offset":0,"length":5,"confidenceScore":0.8}],"warnings":[]},{"id":"3","entities":[{"text":"Four","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"4","entities":[{"text":"Five","category":"Quantity","subcategory":"Number","offset":0,"length":4,"confidenceScore":0.8}],"warnings":[]},{"id":"5","entities":[{"text":"Six","category":"Quantity","subcategory":"Number","offset":0,"length":3,"confidenceScore":0.8}],"warnings":[]}],"errors":[{"id":"All","error":{"code":"InvalidArgument","message":"The
request contains a warning.","innererror":{"code":"InvalidDocumentBatch","message":"The
number of documents in the request have exceeded the data limitations. See
https://aka.ms/text-analytics-data-limits for additional information"}}}],"modelVersion":"2020-04-01"}'
headers:
apim-request-id: 1dd2fff9-8681-43db-a4a2-550d2ce86329
content-type: application/json; charset=utf-8
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=6
date: Thu, 30 Apr 2020 18:38:29 GMT
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-content-type-options: nosniff
x-envoy-upstream-service-time: '74'
status:
code: 200
message: OK
url: https://westus2.ppe.cognitiveservices.azure.com/text/analytics/v3.0/entities/recognition/general?showStats=false
version: 1
Loading