# Python Flask and Snap! Send

**URL:** <https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098>\
**Category:** Snap! Editor\
**Created:** [May 6, 2022, 2:09am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098 "2022-05-06T02:09:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 6, 2022, 2:09am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/1 "2022-05-06T02:09:25Z")

</div>

Im trying to use this in Snap!

![untitled script pic (3)](https://cdn.forum.snap.berkeley.edu/original/3X/f/5/f56eba35c7ee5f472e935b4582e95cf128a5ee82.png)

to send audio to my python database.  
What Python code would I use to retrieve the data from the SEND part of the block?  
(Yes I know there is no URL in the image)

---

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 6, 2022, 2:15am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/2 "2022-05-06T02:15:54Z")

</div>

@18001767679  
@348663451y

---

<div class="post-metadata">

**Author:** ![pajamaclaws21](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/pajamaclaws21/32/15014_2.png) [@pajamaclaws21](https://forum.snap.berkeley.edu/u/pajamaclaws21)\
**Post date:** [May 6, 2022, 2:25am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/3 "2022-05-06T02:25:37Z")

</div>

Well, you could send the data as a header and grab the data from the received header…

[https://stackoverflow.com/questions/6260457/using-headers-with-the-python-requests-librarys-get-method](https://stackoverflow.com/questions/6260457/using-headers-with-the-python-requests-librarys-get-method)

---

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 6, 2022, 2:26am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/4 "2022-05-06T02:26:38Z")

</div>

I'm sending data via the block, not Python.

---

<div class="post-metadata">

**Author:** ![pajamaclaws21](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/pajamaclaws21/32/15014_2.png) [@pajamaclaws21](https://forum.snap.berkeley.edu/u/pajamaclaws21)\
**Post date:** [May 6, 2022, 2:27am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/5 "2022-05-06T02:27:47Z")

</div>

Yes. I am suggesting you use the block’s header section along with a key-value pair where the value is your “audio” variable, or, if it’s a list, the JSON of that variable.

EDIT: Sorry for the lack of visuals, I’m not near a computer now and can’t use Snap_!_ on mobile easily

---

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 6, 2022, 2:28am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/6 "2022-05-06T02:28:41Z")

</div>

How would I receive this data in Python?

---

<div class="post-metadata">

**Author:** ![pajamaclaws21](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/pajamaclaws21/32/15014_2.png) [@pajamaclaws21](https://forum.snap.berkeley.edu/u/pajamaclaws21)\
**Post date:** [May 6, 2022, 2:32am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/7 "2022-05-06T02:32:36Z")

</div>

Hmm. Sorry, I’m just now realizing the link I provided wasn’t accurate, haha. I will look into it tomorrow when I have access to a computer. 😂

---

<div class="post-metadata">

**Author:** ![18001767679](https://forum.snap.berkeley.edu/letter_avatar_proxy/v4/letter/1/839c29/32.png) [@18001767679](https://forum.snap.berkeley.edu/u/18001767679)\
**Post date:** [May 6, 2022, 3:46am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/8 "2022-05-06T03:46:49Z")

</div>

uhh? \<\>p\>\>\>

---

<div class="post-metadata">

**Author:** ![pajamaclaws21](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/pajamaclaws21/32/15014_2.png) [@pajamaclaws21](https://forum.snap.berkeley.edu/u/pajamaclaws21)\
**Post date:** [May 6, 2022, 11:46am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/9 "2022-05-06T11:46:12Z")

</div>

This is probably a solution! It's an edited version of the code from [Simple API using Flask. Easy steps to create a simple API in… | by Renu Khandelwal | Level Up Coding](https://levelup.gitconnected.com/simple-api-using-flask-bc1b7486af88).

```auto
from flask import Flask, jsonify, request
app= Flask( __name__ )

@app.route("/whatever-you-want", methods=["POST"])
def whatever-you-want():
  if request.method=='POST':
    posted_data = request.get_json()
    data = str(posted_data['data']) # The actual data you want! It's sent through the "send" input on the block.
    return(jsonify("whatever-you-want"))

```

---

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 6, 2022, 11:34pm UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/10 "2022-05-06T23:34:56Z")

</div>

```auto
400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

```

---

<div class="post-metadata">

**Author:** ![pajamaclaws21](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/pajamaclaws21/32/15014_2.png) [@pajamaclaws21](https://forum.snap.berkeley.edu/u/pajamaclaws21)\
**Post date:** [May 7, 2022, 3:07am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/11 "2022-05-07T03:07:27Z")

</div>

Hmm. I didn't get any errors when I was running it earlier, I will look into it tomorrow.

---

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 9, 2022, 10:01pm UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/12 "2022-05-09T22:01:23Z")

</div>

(2 days later)

---

<div class="post-metadata">

**Author:** ![slate\_technologies](https://forum.snap.berkeley.edu/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@slate\_technologies](https://forum.snap.berkeley.edu/u/slate_technologies)\
**Post date:** [May 9, 2022, 10:09pm UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/13 "2022-05-09T22:09:21Z")

</div>

Lol

---

<div class="post-metadata">

**Author:** ![pajamaclaws21](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/pajamaclaws21/32/15014_2.png) [@pajamaclaws21](https://forum.snap.berkeley.edu/u/pajamaclaws21)\
**Post date:** [May 10, 2022, 1:07pm UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/14 "2022-05-10T13:07:40Z")

</div>

Apologies- I've kinda been preoccupied with other projects.

---

<div class="post-metadata">

**Author:** ![joecooldoo](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/joecooldoo/32/46163_2.png) [@joecooldoo](https://forum.snap.berkeley.edu/u/joecooldoo)\
**Post date:** [May 11, 2022, 12:41am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/15 "2022-05-11T00:41:07Z")

</div>

Totally understandable.

---

<div class="post-metadata">

**Author:** ![348663451y](https://forum.snap.berkeley.edu/letter_avatar_proxy/v4/letter/3/8baadc/32.png) [@348663451y](https://forum.snap.berkeley.edu/u/348663451y)\
**Post date:** [May 17, 2022, 12:42am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/16 "2022-05-17T00:42:36Z")

</div>

Do you still need help? If so, I've a question: Why not just use the URL parameters to send data like so:

```auto
@app.route(url.com/<data>/)
def recieveData(data):
    pass

```

(Correct my code if I'm wrong. I haven't done any coding whatsoever for like the past few months. Although you may have noticed that as I just kinda quit Snap! for a while.)

---

<div class="post-metadata">

**Author:** ![warped\_wart\_wars](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/warped_wart_wars/32/11997_2.png) [@warped\_wart\_wars](https://forum.snap.berkeley.edu/u/warped_wart_wars)\
**Post date:** [May 17, 2022, 1:01am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/17 "2022-05-17T01:01:18Z")

</div>

I think there's a limit on the length a URL can be.

---

<div class="post-metadata">

**Author:** ![348663451y](https://forum.snap.berkeley.edu/letter_avatar_proxy/v4/letter/3/8baadc/32.png) [@348663451y](https://forum.snap.berkeley.edu/u/348663451y)\
**Post date:** [May 17, 2022, 1:55am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/18 "2022-05-17T01:55:05Z")

</div>

Within Google or Snap!? If you're talking about Google, I doubt he will exceed the limits considering the highly long URLs I've seen. And in Snap! I tried it out and it doesn't seem to say anything if I put in a really long string in the URL block (although, to be fair, it's not like the string is an actual URL so maybe that might be affecting something though I think not).

---

<div class="post-metadata">

**Author:** ![warped\_wart\_wars](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/warped_wart_wars/32/11997_2.png) [@warped\_wart\_wars](https://forum.snap.berkeley.edu/u/warped_wart_wars)\
**Post date:** [May 17, 2022, 2:02am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/19 "2022-05-17T02:02:49Z")

</div>

In general. I'm going to test putting the entire `morphic.txt` in a URL.

Edit:  
 ![Rock Paper Scissors API script pic](https://cdn.forum.snap.berkeley.edu/optimized/3X/a/2/a26187e0b919925056911c3bca1c0223c881f1de_2_517x48.png)

 ![Screenshot (66)](https://cdn.forum.snap.berkeley.edu/original/3X/0/9/09737214b3ce70b7416bb6b0756cb353ac0a6a6b.png)

---

<div class="post-metadata">

**Author:** ![system](https://cdn.forum.snap.berkeley.edu/original/2X/d/dc8cfa4b1c99bd810b188b58c718084d8f47e271.svg) [@system](https://forum.snap.berkeley.edu/u/system)\
**Post date:** [June 16, 2022, 2:02am UTC](https://forum.snap.berkeley.edu/t/python-flask-and-snap-send/11098/20 "2022-06-16T02:02:51Z")

</div>

Closed on June 16, 2022, 2:02am UTC

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