Forums

Internal sever error

Hi, I get a 500 error with the following error message

2021-02-08 20:43:23,510: Exception on /go [POST]
Traceback (most recent call last):
  File "/home/grumpyp/.virtualenvs/onpage_functions.py", line 54, in count_words
    size_tag = size_tags(html_text)
  File "/home/grumpyp/.virtualenvs/onpage_functions.py", line 108, in size_tags
    h1s = text.find_all('h1')
AttributeError: 'str' object has no attribute 'find_all'
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/home/grumpyp/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/grumpyp/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/grumpyp/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/grumpyp/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/grumpyp/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/grumpyp/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/grumpyp/.virtualenvs/main.py", line 14, in hello_world
    words = onpage_functions.count_words(crawl_results[0],results, keyword, crawl_results[1])
  File "/home/grumpyp/.virtualenvs/onpage_functions.py", line 77, in count_words
    if result_desktop_json["error"] or result_mobile_json["error"]:
KeyError: 'error'

It works on my local machine perfectly so I really don't know what to do and where to start. If i open my app file it says syntax error in one row which looks somehow like that

kw_häufigkeit = tf_idf(text_str, keyword)

Syntax error is because of non ASCII character in the variable name (it's the linter complaining), but it shouldn't be the cause of this error. It looks like a chain of errors which starts with calling find_all on string which is not allowed, which leads to one of the dicts keeping json results not having error key. You should probably start with figuring out why text is a string.

Hey thanks for your help. I gonna doublecheck but it works on my local machine so thats why im a bit wondering.

EDIT: No clue why its not working, on my local machine it is all fine.

You're probably dealing with different data between your local machine and PythonAnywhere. Follow the data back to find out why it is not what your code expects.

No i don't. I give the same input as I do on the local machine.

It's super weird.

Something is different, otherwise you wouldn't be getting different results. Follow the data back from the error to find out what it is and why it's different.

I will upload the files again and put the same input in to test.

Edit : Still not working. Tried to modify the code - still not working. I also don't understand the erros. If the error is

if result_desktop_json["error"] or result_mobile_json["error"]:
KeyError: 'error'

why would that be if i have an else in the code? It obviously must be something with my configuration instead of the code i'd say

that error means that in the result_desktop_json or the result_mobile_json, that dictionary doesn't have an 'error' key.

Well it does all not make sense to me.

I did exactly the same on my local machine than here. What can i actually do know? Or what could be the reason that it doesn't work? Does requests work? I crawl several pages and call APIs. My guess would be that something is not coming back or blocked.

Try printing out the contents of the two variables and see what they contain. From there you may be able to trace back to what the problem is.