Title: raised UnicodeEncodeError when printing GCloudError exception · Issue #2346 · googleapis/google-cloud-python · GitHub
Open Graph Title: raised UnicodeEncodeError when printing GCloudError exception · Issue #2346 · googleapis/google-cloud-python
X Title: raised UnicodeEncodeError when printing GCloudError exception · Issue #2346 · googleapis/google-cloud-python
Description: When exception was received from google storage and UnicodeEncodeError exception was raised try: client = storage.Client() bucket = client.get_bucket(bucket_name) except exceptions.NotFound as e: print e raised unexpected: UnicodeEncodeE...
Open Graph Description: When exception was received from google storage and UnicodeEncodeError exception was raised try: client = storage.Client() bucket = client.get_bucket(bucket_name) except exceptions.NotFound as e: p...
X Description: When exception was received from google storage and UnicodeEncodeError exception was raised try: client = storage.Client() bucket = client.get_bucket(bucket_name) except exceptions.NotFound as e: p...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/2346
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"raised UnicodeEncodeError when printing GCloudError exception","articleBody":"When exception was received from google storage and UnicodeEncodeError exception was raised\n\n``` python\ntry:\n client = storage.Client()\n bucket = client.get_bucket(bucket_name)\nexcept exceptions.NotFound as e:\n print e\n```\n\nraised \n\n```\nunexpected: UnicodeEncodeError('ascii', u'502 \u003c!DOCTYPE html\u003e\\n\u003chtml lang=en\u003e\\n \u003cmeta charset=utf-8\u003e\\n \u003cmeta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\"\u003e\\n \u003ctitle\u003eError 502 (Server Error)!!1\u003c/title\u003e\\n \u003cstyle\u003e\\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* \u003e body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\\n \u003c/style\u003e\\n \u003ca href=//www.google.com/\u003e\u003cspan id=logo aria-label=Google\u003e\u003c/span\u003e\u003c/a\u003e\\n \u003cp\u003e\u003cb\u003e502.\u003c/b\u003e \u003cins\u003eThat\\u2019s an error.\u003c/ins\u003e\\n \u003cp\u003eThe server encountered a temporary error and could not complete your request.\u003cp\u003ePlease try again in 30 seconds. \u003cins\u003eThat\\u2019s all we know.\u003c/ins\u003e\\n (GET https://www.googleapis.com/storage/v1/b/anura-recordings-ar?projection=noAcl)', 1445, 1446, 'ordinal not in range(128)')\n```\n\nThis is the unicode string that caused the problem -\u003e `That\\u2019s all we know.`\n\nThe problem seems to be the `__str__` function in your base exception class. \n\n``` python\nclass GCloudError(Exception):\n ....\n def __str__(self):\n return '%d %s' % (self.code, self.message)\n```\n\nHOW TO REPRODUCE\n\n``` python\ntry:\n a = u'That\\u2019s all we know'\n print a\n raise exceptions.NotFound(a)\nexcept exceptions.GCloudError as e:\n print e\n```\n\nwhich gives\n\n```\n$ python test_gs2.py\nThat’s all we know\nTraceback (most recent call last):\n File \"test_gs2.py\", line 11, in \u003cmodule\u003e\n print e\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\u2019' in position 8: ordinal not in range(128)\n```\n","author":{"url":"https://github.com/cesterlizi","@type":"Person","name":"cesterlizi"},"datePublished":"2016-09-19T15:28:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2346/google-cloud-python/issues/2346"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d0f30f10-6d56-634d-b32a-7872c18b7249 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D668:247EB:1485E05:1BC297E:6A4D748C |
| html-safe-nonce | fe9065aee35340ce2fbbecb42c7d33618533013f1c74378078b48d76103cd77b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjY4OjI0N0VCOjE0ODVFMDU6MUJDMjk3RTo2QTRENzQ4QyIsInZpc2l0b3JfaWQiOiIyNTI2OTE1MzkzMDE3OTY3NzU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 46819a01825869443cdf7b312052fec4e88e208febbe995f3d1026b21a5c3955 |
| hovercard-subject-tag | issue:177816872 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/2346/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80f0aab0514c6edae09f087d243a97e47787edbaf89c70fe0cc0e3978e3fe25c/googleapis/google-cloud-python/issues/2346 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80f0aab0514c6edae09f087d243a97e47787edbaf89c70fe0cc0e3978e3fe25c/googleapis/google-cloud-python/issues/2346 |
| og:image:alt | When exception was received from google storage and UnicodeEncodeError exception was raised try: client = storage.Client() bucket = client.get_bucket(bucket_name) except exceptions.NotFound as e: p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cesterlizi |
| hostname | github.com |
| expected-hostname | github.com |
| None | c78260c7b3f4ac4b0356c8208537f05406a3a2d46a9ec3f735b372dcc519c39e |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 399fff412f48461d435721c009efc17ea44be72f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width