#Rendering discord html file with a flask route

9 messages · Page 1 of 1 (latest)

woeful marten
#

I found a website that if you put the link of the discord html file url into as an argument, it renders the html file:
https://mahto.id/chat-exporter?url=https://cdn.discordapp.com/attachments/1057723577815801866/1063152479761604608/transcript-void-t4-hypicksell.html
I want to recreate this with flask, and i just keep getting 403: Forbitten error

Here is my current code:

@app.route('/chat-exporter', methods=['GET'])
def chat_exporter():
    url = request.args.get('url')
    if url:
        headers = {'User-Agent': 'Mozilla/5.0'}
        response = get(url, headers=headers)
        if response.ok:
            html = response.text
            print(f'html: {html}') # debug
            return render_template('render.html', html=html)
        else:
            return f"Error: {response.status_code} {response.reason}"
    else:
        return "Error: No URL provided"

My flask route

{% block head %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename = 'css/chat_exporter.css') }}">
{% endblock %}
{% block body %}
    {{html|safe}}
{% endblock %}

This is my html file

#

I even tried giving it an header, but still 403 error ::(

high laurel
#

What are you putting as the url?

woeful marten
#

it just runs this code

else:
            return f"Error: {response.status_code} {response.reason}"
#

and gives Error: 403 Forbidden

high laurel
#

Oh, you're getting a 403 when trying to get something from discord's cdn. I thought this was a flask problem 😅

#

I have no idea, sorry