Press enter key to receive http request - flask

I have a problem with Flask. My code is running on a server, and it has the purpose of process HTTP request made from an app built with Flutter. It works, but sometimes I have to press the enter key in the command line to process the request: I tried to add “\n” at the end of the URL, and it works for GET requests (I think this was the solution), but for POST it doesn’t work.
This is the method that should execute when a new POST request is received:
#app.route('/proveedores/agregar', methods = ['POST'])
def proveedorAgre():
content = request.json
print(content)
But sometimes the function doesn’t execute unless I press enter key in the cmd
Someone knows what is happening?

Related

Qt GET request strange response

I'm writing a program to log into a game a get some information from the account.
After making a post request with username and password, I make a get request in the same location in order to download the needed html source.
However, doing qDebug()<<QString(reply->readAll());
prints "\u001F?\b" ,instead of the entire source code of the page.
The get reply has status code 200, and the error() function returns NetworkError(NoError).
For the post and get requests I'm using header information obtained from chrome's network tab in developer options combined with cookies obtained from previous response headers.
I'm doing a get request after the log-in post request because that's what seems to happen in the actual webpage, as displayed in developer options.
The response might be gzipped. Does unzipping happen to yield the expected result?

Django Channels code is working on Chrome but not Firefox

I am writing a chat application using Django and Channels (new websocket implementation for Django). Users first enter a wait room, until at least 3 other people have joined, then they are directed to a chat room. The code works fine for Chrome, but is not working correctly for Firefox. Here is how it works:
On a new connect to the channel/websocket the server checks to see if at least three people are in the wait room (in consumers.py).
If at least three people are present it broadcasts a message to the channel/websocket using the Group function telling them to redirect.
The message is received by the clients and it executes a redirection in javascript.
Here are the steps I’ve taken to debug the problem:
The code works in browsers other than Firefox (e.g. Chrome).
The code works if the first two clients arriving to the wait room are Firefox and the last one (that triggers the server) is Chrome. It redirects all three clients.
If the first two clients are Chrome and the last client (that triggers the server) is Firefox it redirects the Chrome clients but not the Firefox client.
The problem is unlikely to be with the javascript running the redirection because replacing the code with a simple alert message (upon the client receiving the Group statement) is also not working in Firefox (but does work in Chrome). It is as if the Firefox client never receives the Group message when it is the client that triggers the server.
The chat uses channels and works on all browsers including Firefox. It successfully connects, sends messages, receives messages, and disconnects.
Based on these debugging steps I think something is going wrong when Firefox instigates the server code that executes the Group redirect. Do you have any suggestions for what might be going wrong? Do you have any suggestions that would help identify the problem?
Here is the code in consumers.py that I think is causing the problem:
#channel_session_user_from_http
#channel_session
def wait_connect(message):
try:
wait_room, created = WaitRoom.objects.get_or_create(title=title)
except WaitRoom.DoesNotExist:
log.debug('ws room does not exist title=%s', title)
return
Group('wait-'+title, channel_layer=message.channel_layer).add(message.reply_channel)
wait_user,created = wait_room.users.get_or_create(user=message.user)
userlist = WaitUser.objects.filter(wait_room=wait_room,is_active=1)
if len(userlist)>=3:
t = {t['url']='redirecturl'}
Group('wait-'+title, channel_layer=message.channel_layer).send({'text': json.dumps(t)})
Here is the javascript code that is executing the redirect:
$(function() {
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
var chatsock = new ReconnectingWebSocket(ws_scheme + '://' + window.location.host + window.location.pathname);
chatsock.onmessage = function(message) {
var data = JSON.parse(message.data);
window.location.replace(data.url);
};});

ksoap2 - SoapObject 'source not found'

I have a code for the BlackBerry App where the "login" button is clicked to fetch xml data. However nothing turns up when I try to show the response returned from the webservice that accepts username and password. My MDS is selected and the browser shows the internet to be working. However I do not see any disable registration option in the debugger configuration window as some posts suggest. My problem is how to get the server response. In the simulator debug console, no System.println msgs are showing up. Debugging line by line, when it comes to the code
SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
debugger produces the error "Source not found". My focus has actually shifted from getting the server response to actually fixing the path to ksoap2 as it appears not to be found. Any tips on this? Thanks

making WebResponse GetResponse WebBot wait for redirect

I am making a bot that simulates a human user using a specific website.
When the user uses the site here is what happens
the user uploads a file by using the site's Browse button and then clicks Upload
the server responds immediately and the user sees a Please Wait gif
in the meantime the server is evaluating the file for errors. When it is done it redirects, and the user is take to a new .aspx page where they can correct the errors.
What I am not able to do w the bot is make it wait to get the redirect info.
The bot hits the website with this line of code (VB.NET)
Dim Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
The Response has the Please Wait gif in it, not the Errors.aspx page. Somehow I need to make the bot, execute that line of code above then, sorta listen to the same port(?) and wait for the web server to send another response.
Ideas?
I ended up just sleeping the thread, then hitting the url again, repeatedly till I got the response I wanted.

Connecting a desktop application with a website

I made an application using Qt/C++ that reads some values every 5-7 seconds and sends them to a website.
My approach is very simple. I am just reading the values i want to send and then i make an HTTP POST to the website. I also send the username and password to the website.
The problem is that i cannot find out if the request is successful. I mean that if i send the request and server gets it, i will get an HTTP:200 always. For example if the password is not correct, there is no way to know it. It is the way HTTP works.
Now i think i will need some kind of a protocol to take care the communication between the application and the website.
The question is what protocol to use?
If the action performed completes before the response header is sent you have the option of adding a custom status to it. If your website is built on PHP you can call header() to add the custom status of the operation.
header('XAppRequest-Status: complete');
if you can modify the server side script you could do the following
on one end :
You can make the HTTP post request via ajax
and evaluate the result of the ajax request.
On the serve side
On the HTTP request you do your process and if everything goes accordingly you can send data back to the ajax script that called it.
solves your problem .. ?