The application is deployed on heroku. When I run the program on my machine it works fine, but in production I get different errors. In Google Chrome in the console I get the following error:
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
In Firefox the error in the console is as follows
Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I received the following report from Sentry:
Exception gaierror: [Errno 11001] getaddrinfo failed File "urllib3\connection.py", line 169, in _new_conn conn = connection.create_connection( File "urllib3\util\connection.py", line 73, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "socket.py", line 953, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000177DC7693A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed File "urllib3\connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "urllib3\connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "urllib3\connectionpool.py", line 1010, in _validate_conn conn.connect() File "urllib3\connection.py", line 353, in connect conn = self._new_conn() File "urllib3\connection.py", line 181, in _new_conn raise NewConnectionError(
MaxRetryError: HTTPSConnectionPool(host='www.wordreference.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000177DC7693A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) File "requests\adapters.py", line 439, in send resp = conn.urlopen( File "urllib3\connectionpool.py", line 755, in urlopen retries = retries.increment( File "urllib3\util\retry.py", line 574, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause))
ConnectionError: HTTPSConnectionPool(host='www.wordreference.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000177DC7693A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) (5 additional frame(s) were not displayed) ... File "requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "requests\sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "requests\sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "requests\adapters.py", line 516, in send raise ConnectionError(e, request=request)
The most relevant code is below. I don't have much experience and I don't know how to identify the problem, I would be very grateful for any help I can get.
views.py
def translate_word(request, word):
wr = WordReference('es', 'en')
wr_obj = wr.translate(word)
entries = wr_obj['translations'][0]['entries']
twlist = []
for entry in entries:
for dict in entry['to_word']:
if dict['meaning'] not in twlist:
twlist.append(dict['meaning'])
return JsonResponse({"twlist": twlist}, safe=False)
demo.js
translate: (word) => {
fetch(`/translate/${word}`, {
headers:{
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest', //Necessary to work with request.is_ajax()
},
})
.then(response => {
return response.json()
})
.then(data => {
// code to display the data on the html, the error occurs in the previous .then
})
},