sending data from python to flutter - python

I am working on developing a mobile application using flutter and I use the Python language as part of the project. I want to know how to send data between flutter and Python, especially sending data from Python to flutter.
For example if i have Python code like this :
**thisdict** = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
i want to send the value of the dictionary thisdict to flutter How to do that ?

I'm assuming the values stored in the dictionary are read from a database, which means you will hav to implement a RESTful-API on Python using Django's REST Framework or Flask's REST Framework.
Django Rest Framework
Flask-RESTful
This API will read values from the database upon a request and send the data back as a JSON object to the user/API Caller with the data required in the dictionary.
To send HTTP Post or GET Requests you will have to use Flutter-BLoC to send POST as well as GET Requests to an API and then capture the Response.
Flutter BLoC
Here's the documentation on FLutter BLoC.

Related

WSO2 api manager not sending uploaded multiple files to backend server

I have built a python webservices application using flask.
After creation of swagger document, I published the api in WSO2 API manager.
The publish of API and subscription to the API are successful.
I am able to get authentication token as well.
What I am doing
To consume the API, in Postman/Angular application I am uploading 2 excel file
Files are then sent to WSO2 server url which then sends it to python server
When python server receives the file, it parses it.
Does some calculations and returns the response data object.
Now the problem is at step 3. The files received at Python end are not in the excel format. The data of both the file are combined into one FileStorage object.
Please see the snapshot below
Instead of two One FileStorage object received in request.files
I am trying this all in postman as well as with an angular application and both doesn't work.
I even tried it via swagger at published app's page in WSO2 API manager but that also doesn't works.
Sending Files Via WSO2 Swagger
What only works
When I try the Swagger of published app, Or when I consume the services via postman making a request directly to python's server.
I am getting both the files in proper required format.
File received properly when tried with python app's swagger page
Can you please help me to understand as to what I might be doing wrong.
I am using content type as below
'content-type: multipart/form-data;
After some digging up I found my resolution at Multipart form data file upload using WSO2 API manager?
I added the
<messageBuilder contentType="multipart/form-data"
class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageFormatter contentType="multipart/form-data"
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
inside the JSON Message Builders and JSON Message Formatters section in axis2.xml file at
<API-M_HOME>repository\conf\axis2\axis2.xml

Integrate AWS Lex to website(lambda implemented in python runtime)

Im working on a bot and would like to integrate to a website for my project. My Bot is fully functional, lambda fulfillment coded in python runtime. I see example of how to integrate bot implemented in javascript(lambda node runtime) but not able to find help for python implementation.
Does my bot need to be implemented in javascript(lambda node runtime) to be able to integrate with website?
I not very familiar with UI stuff and any help to get me started is appreciated.
Your bot can be written in any language and still be integrated with a website.
You can use an AWS SDK to access the bot or HTTPS calls.
From the documentation for HTTPS calls:
POST /bot/botName/alias/botAlias/user/userId/text HTTP/1.1
Content-type: application/json
{
"inputText": "string",
"requestAttributes": {
"string" : "string"
},
"sessionAttributes": {
"string" : "string"
}
}
Or you can use an SDK. This can be done through the UI layer, using the JavaScript SDK; or through the website back-end, using the SDK that matches your backend. Here's the list of SDKs.
You will be calling these methods from the Lex SDK to use your bot. PostContent is for sending voice, and PostText is for sending text. The response will contain the bots response.
Hope that helps

Convert OAuth token generated with Ruby to usable by Python

This question refers to youtube, specifically youtube analytics API and OAuth flow.
Using a ruby server-side webapp, I have created a token.
I now want to use that token in a client-side python app.
I have the client_secrets.json that generated the token.
I have generated tokens with python before and the format does not match that of the ruby generated token.
Is there existing code or a simple way to convert the ruby formatted token for use in python? Yes, they are both json but the structures are different.
https://developers.google.com/youtube/reporting/guides/authorization/server-side-web-apps
Assuming that you use the same client id and client secret for both ruby and python. The refresh token that you got from one will work in the other.
Raw Oauth response:
{
"access_token" : "ya29.1.AADtN_VSBMC2Ga2lhxsTKjVQ_ROco8VbD6h01aj4PcKHLm6qvHbNtn-_BIzXMw",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/J-3zPA8XR1o_cXebV9sDKn_f5MTqaFhKFxH-3PUPiJ4"
}
Assuming you are using the client libraries then the issue you are going to have is how the different libraries store there credentials and read from them. You are going to have to make your own parser for that.

Get JSON format from adwords api report

So I'm building an application which has a frontend in React and a backend
in python (pyramid framework).
I recently integrated the google adwords api to query custom reports (doing this in python).
I'm able to get a report from the api by making a query.
However, the response comes either in xml or csv format. The api doesn't support json response at the moment.
My question is: how can I get the data to json format and send it back to my frontend so I can display it in my webapp?

How to write a python program to accept http post requests in JSON format and respond back in JSON format?

Mongodb and all related technologies but (in the last 2 weeks) I have learnt python, mongo db and have written code in python to read csv files, do data wrangling and write the date into mongodb. This part is done.
Now my app sends http requests in JSON format to get the data but I am not sure how to write a python code which listens to this http request, collect the query, fill up with answers and send back the data (answers) in json format. Should I use any frameworks like django or just a simple python program can do this?
Listening for an HTTP request should be done by your web server. I definitely would not recommend writing that part yourself.
If your application serves only a single request URL, with no user authentication, then it might be simple enough to write your own program from scratch.
But if it's more complex than that, i.e. if you want to serve multiple pages or you want your users to log in, I would recommend using a framework such as Django.

Categories