1

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
  })
},
Brian Destura
  • 11,487
  • 3
  • 18
  • 34
  • Looks like connection to `www.wordreference.com` is timed out, check if it is accessible from production machine – Adithya Sep 23 '21 at 04:33
  • Thank you very much @Adithya, this is correct, I run the command wr = WordReference('es', 'en') and I don't get response, I get the following error File "/app/.heroku/python/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn conn = connection.create_connection( File "/app/.heroku/python/lib/python3.9/site-packages/urllib3/util/connection.py", line 96, in create_connection raise err File "/app/.heroku/python/lib/python3.9/site-packages/urllib3/util/connection.py", line 86, in create_connection sock.connect(sa) OSError: [Errno 101] Network is unreachable – Rodrigo Yanez Sep 23 '21 at 12:21

0 Answers0