# Webhooks Python Flask

**URL:** <https://forums.plex.tv/t/webhooks-python-flask/686141>\
**Category:** General Discussions\
**Tags:** webhooks\
**Created:** [February 2, 2021, 7:50pm UTC](https://forums.plex.tv/t/webhooks-python-flask/686141 "2021-02-02T19:50:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![th9luckyone](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@th9luckyone](https://forums.plex.tv/u/th9luckyone)\
**Post date:** [February 2, 2021, 7:50pm UTC](https://forums.plex.tv/t/webhooks-python-flask/686141/1 "2021-02-02T19:50:16Z")

</div>

Hello Plex Community

i have struggled for two evenings with flask to get the webhooks working. Maybe some one can also use this as a starting point.

I have used:

- Python 3 as venv and flask

My Webhook in plex looks like that

```auto
http://192.168.188.26:5000/plex

```

Python Flask Script

```auto
from flask import Flask, request
import json

app = Flask( __name__ )

@app.route('/plex', methods=['POST'])
def listener():
    data = request.form.getlist('payload')
    m = data[0]
    n = json.dumps(m)
    o = json.loads(n)
    p = json.loads(o)
    print("event : "+p['event'])
    print("user : "+str(p['user']))
    print("owner : "+str(p['owner']))
    print("Account title : "+p["Account"]['title'])
    print("Server title : "+p["Server"]["title"])
    print("Player title : "+p["Player"]["title"])
    print("Metadata librarySectionTitle : "+p["Metadata"]["librarySectionTitle"])
    return "Ack"

if __name__ == " __main__":
    app.run(debug=True,host='0.0.0.0')

```

The output looks like that

```auto
* Serving Flask app "plex" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 125-568-481
event : media.resume
user : True
owner : True
Account title : th9luckyone
Server title : Berlin
Player title : Safari
Metadata librarySectionTitle : TV Shows
192.168.188.24 - - [02/Feb/2021 19:42:22] "POST /plex HTTP/1.0" 200 -

```

**As shown in the output. This is not for production. Only use this for testing.**  
Follow the deployment guide on flask. Also use TLS if you are not just in your own network 😉

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [May 13, 2021, 9:44pm UTC](https://forums.plex.tv/t/webhooks-python-flask/686141/3 "2021-05-13T21:44:14Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
