[Fixed]-HTTP Error 500: internal server error

1👍

Try:

import urllib.request
from urllib.error import HTTPError

url = "<enter_URL_here>"

try:
   res = urllib.request.urlopen(url)
except HTTPError as e:
    content = e.read()
    print("HTTP error encountered while reading URL")

0👍

You will need to get a session cookie and then read the generated cookie for that session.

The best way to go about that is to fetch the page with the form first, saving all cookies. You can use cookielib for that as demonstrated here. If you want to make life easier for yourself, use requests as well instead of urllib. The code then becomes a lot simpler.

To get the CSRF token, you can scrape the form page with BeautifulSoup. There are lots of tutorials for this which you can easily find on Google.

👤jsfan

Leave a comment