# Python Flask and Snap! Send

Im trying to use this in Snap!

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)

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

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

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

How would I receive this data in Python?

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.

uhh? <>p>>>

This is probably a solution! It's an edited version of the code from https://levelup.gitconnected.com/simple-api-using-flask-bc1b7486af88.

from flask import Flask, jsonify, request

@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"))

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


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

(2 days later)

Lol

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

Totally understandable.

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

@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.)

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

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).

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

Edit:

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