seanmorley15/AdventureLog

[BUG] Unable to get anything from Wikipedia

Closed this issue · 3 comments

Hi all, and thank you for this fantastic software !

Description
I have a problem to get content from Wikipedia. Buttons "Generate description" and "Fetch image" (from wikipedia) don't work at all on my server.

To Reproduce
Steps to reproduce the behavior:

  1. Add a new edventure
  2. Entry Bordeaux in the name (a famous city in France)
  3. Click on "Generate description"
  4. Nothing append

Expected behavior
The description should be populated with wikipedia content.

Docker Compose
Docker is not used.

Additional context
AdventureLog is behind 2 reverse proxy (NGINX) and a VPN. My instance is self hosted and installed with Yunohost project. The version is 0.10.0.

Log
Here the F12 from my browser :

XHRGET
https://adventure.rps.ovh/api/generate/desc?name=bordeaux

[HTTP/2 500  338ms]

Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data
    ae Immutable
    AsyncFunctionThrow self-hosted:804
    Immutable 13
    forEach self-hosted:157
    Immutable 2

Here log from the backend:

Internal Server Error: /api/generate/desc/
Traceback (most recent call last):
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/requests/models.py", line 976, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/rest_framework/views.py", line 515, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/rest_framework/views.py", line 475, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/rest_framework/views.py", line 486, in raise_uncaught_exception
    raise exc
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/rest_framework/views.py", line 512, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/backend/server/adventures/views/generate_description_view.py", line 15, in desc
    name = self.get_search_term(name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/backend/server/adventures/views/generate_description_view.py", line 42, in get_search_term
    data = response.json()
           ^^^^^^^^^^^^^^^
  File "/var/www/adventurelog/venv/lib/python3.11/site-packages/requests/models.py", line 980, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

In the same time I've tested this API call with curl and it works, so I guess that I don't have connection problem:

❯ curl "https://en.wikipedia.org/w/api.php?origin=*&action=query&prop=extracts&exintro&explaintext&format=json&redirects=1&titles=bordeaux"


{"batchcomplete":"","query":{"normalized":[{"from":"bordeaux","to":"Bordeaux"}],"pages":{"4097":{"pageid":4097,"ns":0,"title":"Bordeaux","extract":"Bordeaux ( bor-DOH; French: [b\u0254\u0281do] ; Gascon Occitan: Bord\u00e8u [bu\u027e\u02c8\u00f0\u025bw]; Basque: Bordele) is a city on the river Garonne in the Gironde department, southwestern France. A port city, it is the capital of the Nouvelle-Aquitaine region, as well as the prefecture of the Gironde department. Its inhabitants are called \"Bordelais\" (masculine) or \"Bordelaises\" (feminine). The term \"Bordelais\" may also refer to the city and its surrounding region.\nThe city of Bordeaux proper had a population of 259,809 in 2020 within its small municipal territory of 49 km2 (19 sq mi), but together with its suburbs and exurbs the Bordeaux metropolitan area had a population of 1,376,375 that same year (Jan. 2020 census), the sixth-most populated in France after Paris, Lyon, Marseille, Lille, and Toulouse.\nBordeaux and 27 suburban municipalities form the Bordeaux Metropolis, an indirectly elected metropolitan authority now in charge of wider metropolitan issues. The Bordeaux Metropolis, with a population of 819,604 at the January 2020 census, is the fifth most populated metropolitan council in France after those of Paris, Marseille, Lyon and Lille.\nBordeaux is a world capital of wine: many ch\u00e2teaux and vineyards stand on the hillsides of the Gironde, and the city is home to the world's main wine fair, Vinexpo. Bordeaux is also one of the centers of gastronomy and business tourism for the organization of international congresses. It is a central and strategic hub for the aeronautics, military and space sector, home to major companies such as Dassault Aviation, ArianeGroup, Safran and Thales. The link with aviation dates back to 1910, the year the first airplane flew over the city. A crossroads of knowledge through university research, it is home to one of the only two megajoule lasers in the world, as well as a university population of more than 130,000 students within the Bordeaux Metropolis.\nBordeaux is an international tourist destination for its architectural and cultural heritage with more than 362 historic monuments, making it, after Paris, the city with the most listed or registered monuments in France. The \"Pearl of Aquitaine\" has been voted European Destination of the year in a 2015 online poll. The metropolis has also received awards and rankings by international organizations such as in 1957, Bordeaux was awarded the Europe Prize for its efforts in transmitting the European ideal. \nIn June 2007, the Port of the Moon in historic Bordeaux was inscribed on the UNESCO World Heritage List, for its outstanding architecture and urban ensemble and in recognition of Bordeaux's international importance over the last 2000 years. Bordeaux is also ranked as a Sufficiency city by the Globalization and World Cities Research Network."}}}}% ```


Some users experiment same problem ?

I am also seeing 500 errors when the the front end tries to get Wikipedia data.

Appears their API now required a user agent so it was being blocked. Just added one now in Dev and am testing a patch 🙂

Great! Thank you