File tree Expand file tree Collapse file tree 5 files changed +40
-1
lines changed
Expand file tree Collapse file tree 5 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ TargetProcessingTimeout
1212TargetStatusProcessing
1313Ubuntu
1414UnknownTarget
15+ UnknownVWSErrorPossiblyBadName
1516api
1617args
1718ascii
Original file line number Diff line number Diff line change 22Tools for managing result codes.
33"""
44
5+ import json
6+
57from requests import Response
68
79from vws .exceptions import (
1618 TargetStatusNotSuccess ,
1719 TargetStatusProcessing ,
1820 UnknownTarget ,
21+ UnknownVWSErrorPossiblyBadName ,
1922)
2023
2124
@@ -31,8 +34,18 @@ def raise_for_result_code(
3134 response: A response from Vuforia.
3235 expected_result_code: See
3336 https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.html#How-To-Interperete-VWS-API-Result-Codes
37+
38+ Raises:
39+ ~vws.exceptions.UnknownVWSErrorPossiblyBadName: Vuforia returns an HTML
40+ page with the text "Oops, an error occurred". This has been seen to
41+ happen when the given name includes a bad character.
3442 """
35- result_code = response .json ()['result_code' ]
43+ try :
44+ result_code = response .json ()['result_code' ]
45+ except json .decoder .JSONDecodeError as exc :
46+ assert 'Oops' in response .text
47+ raise UnknownVWSErrorPossiblyBadName () from exc
48+
3649 if result_code == expected_result_code :
3750 return
3851
Original file line number Diff line number Diff line change 66from requests import Response
77
88
9+ class UnknownVWSErrorPossiblyBadName (Exception ):
10+ """
11+ Exception raised when VWS returns an HTML page which says "Oops, an error
12+ occurred".
13+
14+ This has been seen to happen when the given name includes a bad character.
15+ """
16+
17+
918class ConnectionErrorPossiblyImageTooLarge (
1019 requests .exceptions .ConnectionError ,
1120):
Original file line number Diff line number Diff line change @@ -178,6 +178,10 @@ def add_target(
178178 ~vws.exceptions.ProjectInactive: The project is inactive.
179179 ~vws.exceptions.RequestTimeTooSkewed: There is an error with the
180180 time sent to Vuforia.
181+ ~vws.exceptions.UnknownVWSErrorPossiblyBadName: Vuforia returns an
182+ HTML page with the text "Oops, an error occurred". This has
183+ been seen to happen when the given name includes a bad
184+ character.
181185 """
182186 image_data = image .getvalue ()
183187 image_data_encoded = base64 .b64encode (image_data ).decode ('ascii' )
Original file line number Diff line number Diff line change 2525 TargetStatusNotSuccess ,
2626 TargetStatusProcessing ,
2727 UnknownTarget ,
28+ UnknownVWSErrorPossiblyBadName ,
2829)
2930
3031
@@ -52,6 +53,17 @@ def test_invalid_given_id(vws_client: VWS) -> None:
5253 assert exc .value .response .status_code == codes .NOT_FOUND
5354
5455
56+ def test_add_bad_name (vws_client : VWS , high_quality_image : io .BytesIO ) -> None :
57+ """
58+ When a name with a bad character is given, an
59+ ``UnknownVWSErrorPossiblyBadName`` exception is raised.
60+ """
61+ max_char_value = 65535
62+ bad_name = chr (max_char_value + 1 )
63+ with pytest .raises (UnknownVWSErrorPossiblyBadName ):
64+ vws_client .add_target (name = bad_name , width = 1 , image = high_quality_image )
65+
66+
5567def test_request_quota_reached () -> None :
5668 """
5769 See https://github.com/adamtheturtle/vws-python/issues/822 for writing
You can’t perform that action at this time.
0 commit comments