anilabhadatta / educative-viewer

Python-flask based web-app to view courses scraped using educative.io-scraper
MIT License
71 stars 22 forks source link

500 Internal Server Error #10

Open Diez15 opened 1 year ago

Diez15 commented 1 year ago

When using the latest release of educative-viewer or when cloning the latest version and running the python script manually, I get the following error:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

The server correctly lists all the items, but clicking on any of them I get the above error. The python trace is:

SNIP  - - [27/Jun/2023 13:12:59] "POST / HTTP/1.1" 302 -
[27/Jun/2023 13:12:59] "POST / HTTP/1.1" 302 -
[2023-06-27 13:12:59,982] ERROR in app: Exception on /145-replace [GET]
Traceback (most recent call last):
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "SNIP\educative-viewer\educative-viewer.py", line 131, in topics
    rendered_html = render_template(
  File "SNIP\eenv2\lib\site-packages\flask\templating.py", line 147, in render_template
    return _render(
  File "SNIP\eenv2\lib\site-packages\flask\templating.py", line 128, in _render
    rv = template.render(context)
  File "SNIP\eenv2\lib\site-packages\jinja2\environment.py", line 1291, in render
    self.environment.handle_exception()
  File "SNIP\eenv2\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "SNIP\educative-viewer\templates\topics.html", line 35, in top-level template code
    [([(=  include webpage =)])]
  File "SNIP\eenv2\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<unknown>", line 5, in template
jinja2.exceptions.TemplateSyntaxError: Missing end of comment tag
SNIP - - [27/Jun/2023 13:12:59] "GET /145-replace HTTP/1.1" 500 -
[2023-06-27 13:13:00,292] ERROR in app: Exception on /favicon.ico [GET]
Traceback (most recent call last):
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "SNIP\eenv2\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "SNIP\educative-viewer\educative-viewer.py", line 131, in topics
    rendered_html = render_template(
  File "SNIP\eenv2\lib\site-packages\flask\templating.py", line 147, in render_template
    return _render(
  File "SNIP\eenv2\lib\site-packages\flask\templating.py", line 128, in _render
    rv = template.render(context)
  File "SNIP\eenv2\lib\site-packages\jinja2\environment.py", line 1291, in render
    self.environment.handle_exception()
  File "SNIP\eenv2\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "SNIP\educative-viewer\templates\topics.html", line 35, in top-level template code
    [([(=  include webpage =)])]
  File "SNIP\eenv2\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<unknown>", line 5, in template
jinja2.exceptions.TemplateSyntaxError: Missing end of comment tag
SNIP - - [27/Jun/2023 13:13:00] "GET /favicon.ico HTTP/1.1" 500 -

I see that a similar issue was raised in the past and you marked it as fixed, but I am still getting the error. Can you provide any advice?

Diez15 commented 1 year ago

@anilabhadatta can you please take a look and help me resolve this issue? Thank you!

anilabhadatta commented 1 year ago

@Diez15 may have some special characters that are causing issues during rendering. Send me the Html file in a zip format here. Also tell me if it is causing for each topics? Video demonstration will be helpful

[([(= include webpage =)])]

This issue is mostly caused due to Latex or special characters in HTML file.

sahibdhanjal commented 8 months ago

@anilabhadatta - I'm facing a similar issue and was wondering if you had a solution for the same. I have cloned the repository and running it locally using a virtual environment. Unfortunately, it's happening with each and every page and I was wondering if you had a solution for the same?

course.zip

Thank You!

anilabhadatta commented 8 months ago

@sahibdhanjal checking

anilabhadatta commented 8 months ago

@sahibdhanjal the zip file you provided is having issues, you will need to re-scrape because i rescraped and it is working. also use dark mode during scraping

sahibdhanjal commented 8 months ago

Ahh, got it, I'll re-scrape. Thanks a lot for looking into it, really appreciate it 👍🏻

anilabhadatta commented 8 months ago

@sahibdhanjal some updates were added as well. do pull

sahibdhanjal commented 8 months ago

Perfect, thanks man!

iexa commented 7 months ago

The simplest fix for this bug is by changing the comment delimiters @ line 18-19 to this:

app.jinja_env.comment_start_string = "{[(#"
app.jinja_env.comment_end_string = "#)]}"

Thanks for the effort. The code is a bit hard to understand though at first sight. And the sidebar could be more transparent or automatically hidden so as not to obstruct the main view.

anilabhadatta commented 7 months ago

@iexa thanks i will update the jinja bug. Also refer v3-dev branch. New features were added and regarding the sidebar, will look a look for enhancement. Also code is very unreadable at this moment, will fix it in coming days.

iexa commented 7 months ago

If you have the capacity you could try adding a light mode as well, the stuff I got are all light mode-scraped unfortunately :(

Would be great to use rar or zip files as well - I mean using a (list of) compressed rar / zip files, as the main data source the same as you do now but with folders / files. python's build in zipfile plus the 3rd party rarfile module would be fine. Reading the archive you can build up a list of links and when the actual html file would be read then it would be unpacked (to the system's temp folder - and read from there).

Or if you can make the code more humanely understandable I can add these features to your code, as I was thinking on making the same but using clean code principles as much as possible.

anilabhadatta commented 7 months ago

@iexa if you want you can make changes to the existing code. Changes should be made to dev branch. I am not getting much time to cleanup the code. I will try to do it. But if you want to participate then I will leave it up to you to refactor the code and the features that you want to implement.

But do remember the zip features should be an optional one, the current architecture should remain stable.

anilabhadatta commented 7 months ago

@iexa currently i am busy fixing and implementing features in the scraper. I will see if i can make the code readable.

sahibdhanjal commented 7 months ago

The simplest fix for this bug is by changing the comment delimiters @ line 18-19 to this:

app.jinja_env.comment_start_string = "{[(#"
app.jinja_env.comment_end_string = "#)]}"

Thanks for the effort. The code is a bit hard to understand though at first sight. And the sidebar could be more transparent or automatically hidden so as not to obstruct the main view.

Thanks @iexa , this worked for me 👍🏻

anilabhadatta commented 6 months ago

@iexa refer to the latest commit on v4-dev branch, a lot of cleanup was done, should help you now understanding the code.