Title: JSONDecodeError when getting/polling a 202/Conversion in progress response · Issue #21 · ConvertAPI/convertapi-library-python · GitHub
Open Graph Title: JSONDecodeError when getting/polling a 202/Conversion in progress response · Issue #21 · ConvertAPI/convertapi-library-python
X Title: JSONDecodeError when getting/polling a 202/Conversion in progress response · Issue #21 · ConvertAPI/convertapi-library-python
Description: I'm using the asynchronous conversion mode and I'm using the convertpi.client.get method to poll the conversion result. I'm polling the results only after receiving the webhook confirmation, understanding that the conversion process woul...
Open Graph Description: I'm using the asynchronous conversion mode and I'm using the convertpi.client.get method to poll the conversion result. I'm polling the results only after receiving the webhook confirmation, unders...
X Description: I'm using the asynchronous conversion mode and I'm using the convertpi.client.get method to poll the conversion result. I'm polling the results only after receiving the webhook confirma...
Opengraph URL: https://github.com/ConvertAPI/convertapi-library-python/issues/21
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JSONDecodeError when getting/polling a 202/Conversion in progress response","articleBody":"I'm using the [asynchronous conversion mode](https://www.convertapi.com/doc/async) and I'm using the [convertpi.client.get](https://github.com/ConvertAPI/convertapi-python/blob/392a48e637fa13f3aeb3a1f807b50f566b25c82f/convertapi/client.py#L8) method to poll the conversion result.\r\n\r\nI'm polling the results only after receiving the webhook confirmation, understanding that the conversion process would have been successful in this case.\r\n\r\nFor some reason, when polling results from the API **after the webhook confirmation**, I'm getting a response different than 200 OK. These are the possible status codes:\r\n\r\n* 200 Conversion is successful. Response is a conversion result.\r\n* 202 Conversion in progress.\r\n* 404 JobId is invalid or response is expired.\r\n* 503 No concurrent poll requests are allowed..\r\n* 5XX Conversion error. Response is an error message.\r\n\r\nI mostly get 200 OK responses when polling after the confirmation, but there are cases where I get a 202 Accepted with blank content. I suppose I'm hitting the API too fast and there is some internal propagation still ongoing, but that is not the point anyway, I could simply retry it and it will work.\r\n\r\nThe problem is that, since the response content is a blank string, and since the get method uses the [handle_response method](https://github.com/ConvertAPI/convertapi-python/blob/392a48e637fa13f3aeb3a1f807b50f566b25c82f/convertapi/client.py#L44) to convert the response to JSON or raise an exception, I'm hitting the unexpected exception _json.decoder.JSONDecodeError_.\r\n\r\nThe other error responses would _raise_for_status_ and fail legitimely. The only problem is with the 202 response, that is a successful status (so it is not raised), but can't be returned as json. I wrote a small wrapper to solve this at my side:\r\n\r\n```python\r\ndef poll_retrieve(job_id):\r\n convertapi.api_secret = settings.CONVERT_API_SECRET\r\n response = requests.get(\r\n convertapi.client.url(f\"job/{job_id}\"),\r\n headers=convertapi.client.headers(),\r\n timeout=convertapi.timeout or None,\r\n )\r\n response.raise_for_status()\r\n if response.status_code == 202:\r\n raise ConversionInProgressError\r\n return response.json()\r\n```\r\n\r\nI could write a pull request, but I want to discuss with you the best approach first: is a new exception (like this ConversionInProgressError) a good idea? Or do you think returning a blank list would work better?","author":{"url":"https://github.com/michelts","@type":"Person","name":"michelts"},"datePublished":"2021-06-01T14:27:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/21/convertapi-library-python/issues/21"}
| 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:b2a1b771-f213-14fd-3f79-e44e1fa71ded |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CD6:2F1E1C:D7EE6F:131823B:697B8161 |
| html-safe-nonce | aa7ac37b13801cef0bea88428774100eb4f2ac0335b4a6517f629ca44ac8dfa8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0Q2OjJGMUUxQzpEN0VFNkY6MTMxODIzQjo2OTdCODE2MSIsInZpc2l0b3JfaWQiOiIzOTY1MTc2NTU4OTA5MDk2Mjg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 11accc0f3b2776212d68987ac2550fb8b2beb3fad4c3e840daacb995d2240b6a |
| hovercard-subject-tag | issue:908353135 |
| 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/ConvertAPI/convertapi-library-python/21/issue_layout |
| twitter:image | https://opengraph.githubassets.com/131d0d385bb19fa0973def357fe82c2e3a520b12216ed5ddbd05b35a3e6f3392/ConvertAPI/convertapi-library-python/issues/21 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/131d0d385bb19fa0973def357fe82c2e3a520b12216ed5ddbd05b35a3e6f3392/ConvertAPI/convertapi-library-python/issues/21 |
| og:image:alt | I'm using the asynchronous conversion mode and I'm using the convertpi.client.get method to poll the conversion result. I'm polling the results only after receiving the webhook confirmation, unders... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michelts |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26ef504c9f5eb2ac26b53c0437f934bbe4c0464979d7386917bd32d9fe70fc7a |
| turbo-cache-control | no-preview |
| go-import | github.com/ConvertAPI/convertapi-library-python git https://github.com/ConvertAPI/convertapi-library-python.git |
| octolytics-dimension-user_id | 37071453 |
| octolytics-dimension-user_login | ConvertAPI |
| octolytics-dimension-repository_id | 132747126 |
| octolytics-dimension-repository_nwo | ConvertAPI/convertapi-library-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 132747126 |
| octolytics-dimension-repository_network_root_nwo | ConvertAPI/convertapi-library-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 | cea9b2b812b4d84ebc94c8a8bd97e2e99a2c0b48 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width