Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 500 server error on invalid API requests #764

Closed
geekygirlsarah opened this issue Jan 27, 2025 · 1 comment · Fixed by #765
Closed

[Bug] 500 server error on invalid API requests #764

geekygirlsarah opened this issue Jan 27, 2025 · 1 comment · Fixed by #765
Assignees
Labels
Experience: Backend good first issue A good issue for anyone new to open source to work on help wanted We'd love to have help working on this issue Priority: Critical Type: Bug

Comments

@geekygirlsarah
Copy link
Member

geekygirlsarah commented Jan 27, 2025

I've been receiving 1-3 emails from someone trying to hit https://codethesaur.us/api/shared/config/config.env/ a couple of times a day. I'm not sure why they are, but the server is reacting in a way I wouldn't be expecting.

(One thought might be turn off the API until we publish more about it, but for now probably properly fixing the error is important too.)

Expected Behavior

The server should react with a proper 400-level error message for an invalid /api request

Actual Behavior

The server reacts with a 500 error and the regular home page

Steps to Reproduce the Problem

(using localhost so @geekygirlsarah doesn't continue to get hit with emails by people doing this on the production server)

  1. Attempt to hit https://localhost:8000/api/shared/config/config.env/

Additional Info

Stack trace:

Internal Server Error: /api/shared/config/config.env/

FileNotFoundError at /api/shared/config/config.env/
[Errno 2] No such file or directory: 'web/thesauruses/config/[config.env/shared.json](http://config.env/shared.json)'

Request Method: GET
Request URL: https://codethesaur.us/api/shared/config/config.env/
Django Version: 4.2.17
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.11.4
Python Path: ['/app/.heroku/python/bin', '/app', '/app/.heroku/python/lib/python311.zip', '/app/.heroku/python/lib/python3.11', '/app/.heroku/python/lib/python3.11/lib-dynload', '/app/.heroku/python/lib/python3.11/site-packages']
Server time: Mon, 27 Jan 2025 04:24:46 +0000
Installed Applications:
['web.apps.WebConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'markdownify.apps.MarkdownifyConfig']
Installed Middleware:
('django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.common.BrokenLinkEmailsMiddleware')


Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/web/views.py", line 431, in api_reference
    response = lang.load_filled_concepts(structure_key, version)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/web/models.py", line 108, in load_filled_concepts
    self.load_concepts(structure_key, version)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/web/models.py", line 91, in load_concepts
    with open(file_path, 'r', encoding='UTF-8') as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: FileNotFoundError at /api/shared/config/config.env/
Exception Value: [Errno 2] No such file or directory: 'web/thesauruses/config/[config.env/shared.json](http://config.env/shared.json)'
Raised during: web.views.api_reference
Request information:
USER: AnonymousUser

GET: No GET data

POST: No POST data

FILES: No FILES data

COOKIES: No cookie data

META:
HTTP_ACCEPT = '*/*'
HTTP_ACCEPT_ENCODING = 'gzip, deflate'
HTTP_CONNECTION = 'close'
HTTP_CONNECT_TIME = '0'
HTTP_HOST = 'codethesaur.us'
HTTP_TOTAL_ROUTE_TIME = '0'
HTTP_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
HTTP_VIA = '1.1 vegur'
HTTP_X_FORWARDED_FOR = 
HTTP_X_FORWARDED_PORT = '443'
HTTP_X_FORWARDED_PROTO = 'https'
HTTP_X_REQUEST_ID = 
HTTP_X_REQUEST_START = '1737951886787'
PATH_INFO = '/api/shared/config/config.env/'
QUERY_STRING = ''
RAW_URI = '/api/shared/config/config.env/'
REMOTE_ADDR = 
REMOTE_PORT = '26629'
REQUEST_METHOD = 'GET'
SCRIPT_NAME = ''
SERVER_NAME = '0.0.0.0'
SERVER_PORT = '56072'
SERVER_PROTOCOL = 'HTTP/1.1'
SERVER_SOFTWARE = 'gunicorn/22.0.0'
gunicorn.socket = 
wsgi.errors = <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f25e91cb8b0>
wsgi.file_wrapper = <class 'gunicorn.http.wsgi.FileWrapper'>
wsgi.input = <gunicorn.http.body.Body object at 0x7f25e8d10210>
wsgi.input_terminated = True
wsgi.multiprocess = True
wsgi.multithread = False
wsgi.run_once = False
wsgi.url_scheme = 'https'
wsgi.version = '(1, 0)'
@geekygirlsarah geekygirlsarah added Experience: Backend good first issue A good issue for anyone new to open source to work on help wanted We'd love to have help working on this issue Priority: Critical Type: Bug labels Jan 27, 2025
@QuentinPace
Copy link
Contributor

Hello, I'd like to claim this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience: Backend good first issue A good issue for anyone new to open source to work on help wanted We'd love to have help working on this issue Priority: Critical Type: Bug
Projects
Development

Successfully merging a pull request may close this issue.

2 participants