I have built an Flask app to upload. It works fine when it runs on my computer but when I upload it to a webservice (tried both Render and pythonanywhere) I get a problem with a request sent to Sofascore API.
url = f"https://www.sofascore.com/api/v1/event/{match_id}"
parsed_url = urlparse(url)
conne = http.client.HTTPSConnection(parsed_url.netloc)
conne.request("GET", parsed_url.path)
jsondata = json.loads(conne.getresponse().read().decode("utf-8"))
It is this part, it works on my computer but not when uploaded. When I visit the site it says
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Do anyone know what the problem is and how to solve it?
Below is the error message from the logs in Render:
Traceback (most recent call last):
Jun 19 01:07:54 PM File "/opt/render/project/src/.venv/lib/python3.11/site- packages/flask/app.py", line 1463, in wsgi_app
Jun 19 01:07:54 PM response = self.full_dispatch_request()
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/opt/render/project/src/.venv/lib/python3.11/site- packages/flask/app.py", line 872, in full_dispatch_request
Jun 19 01:07:54 PM rv = self.handle_user_exception(e)
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/flask/app.py", line 870, in full_dispatch_request
Jun 19 01:07:54 PM rv = self.dispatch_request()
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/opt/render/project/src/.venv/lib/python3.11/site- packages/flask/app.py", line 855, in dispatch_request
Jun 19 01:07:54 PM return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/opt/render/project/src/app.py", line 114, in index
Jun 19 01:07:54 PM jsondata = json.loads(conne.getresponse().read().decode("utf-8"))
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/usr/local/lib/python3.11/json/__init__.py", line 346, in loads
Jun 19 01:07:54 PM return _default_decoder.decode(s)
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
Jun 19 01:07:54 PM obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Jun 19 01:07:54 PM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 19 01:07:54 PM File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
Jun 19 01:07:54 PM raise JSONDecodeError("Expecting value", s, err.value) from None
Jun 19 01:07:54 PMjson.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
Jun 19 01:07:54 PM127.0.0.1 - - [19/Jun/2024:11:07:54 +0000] "GET / HTTP/1.1" 500 265 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
Jun 19 01:07:54 PM127.0.0.1 - - [19/Jun/2024:11:07:54 +0000] "GET /favicon.ico HTTP/1.1" 404 207 "https://emtips.onrender.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
I tried both Render and pythonanywhere, same problem. Also tried to change to Requests instead of http.client but same problem. As it works on my computer I don’t know what the problem is and how to solve it.
1