This question already has answers here:
How can I include special characters in query strings?
(7 answers)
How to send password to REST service securely?
(2 answers)
Closed 1 year ago.
I am using flask and want to create a url which is a post request and contains "username" and "password" as a string in url
#app.route('/login/<username>/<password>')
def login(username,password):
return password
My Url should look like this
http://192.158.42.102:8080/login/iamuser/iamuser##123
But the problem is that password is truncated to "iamuser##123" to "iamuser" , How can I pass the full passowrd as string.
#app.route('/login/<username>/<string:password>')
But still it is returning "iamuser" . Can anyone resolve this issue so that I could pass any string to the url. I do not want to use the form for posting the request
Related
This question already has answers here:
How can I use cookies in Python Requests?
(4 answers)
Closed 3 years ago.
I am trying to get some data from a webpage using python requests which needs to be logged in first.The login http request "response header" contains "set-cookie" parameters which is used for the next http request of the webpage. Could any tell me how to use the set-cookie for the consecutive GET request of the webpage
Try this
session = requests.Session()
response = session.get('http://google.com')
print(session.cookies.get_dict())
Or without using sessions use
response = requests.get('http://google.com')
response.cookies
This question already has answers here:
Get the data received in a Flask request
(23 answers)
Converting Flask form data to JSON only gets first value
(2 answers)
Return JSON response from Flask view
(15 answers)
Closed 4 years ago.
I want to take data from html form with the python flask and send data back at the same html file. Can you help me with an example or some tips? Thank you.
You can use request.form, like the following:
from flask import Flask, request
app = Flask(__name__)
#app.route('/path_form_submits_to', methods=['POST'])
def my_handler():
return request.form.get("field_name", "default value if field isn't there")
This question already has answers here:
Is there an easy way to request a URL in python and NOT follow redirects?
(7 answers)
Closed 4 years ago.
I know that it is possible to check if a URL redirects, as mentioned in the following question and its answer.
How to check if the url redirect to another url using Python
using the following code:
eq = urllib2.Request(url=url, headers=headers)
resp = urllib2.urlopen(req, timeout=3)
redirected = resp.geturl() != url # redirected will be a boolean True/False
However, I have list of Millions of URLs. Currently it is discussed wether one of them is a harmful URL or redirects to a harmful URL.
I want to know if it is possible to check for redirect without opening a direct connection to the redirecting website to avoid creating a connection with a harmful website?
You can do a HEAD request and check the status code. If you are using the third party requests library you can do that like this:
import requests
original_url = '...' # your original url here
response = requests.head(original_url)
if response.is_redirect:
print("Redirecting")
else:
print("Not redirecting")
This question already has answers here:
How can I use JQuery to post JSON data?
(6 answers)
How to get POSTed JSON in Flask?
(13 answers)
Get the data received in a Flask request
(23 answers)
Closed 4 years ago.
This is jquery ajax snippet use to send requests to localhost:5000/query
so this is my jquery snippet
var saveData=$.ajax({
type:"POST",
url:"http://localhost:5000/query",
datatype:"json",
data:{"type":"Company","name":"harshit","cin":"2014UPTC20"},
success:function(resultData){
alert(resultData);
}
});
and i cannot retrieve above sent data from python flask:-
#app.route('/query',methods=['POST'])
def query_neo_dynamic():
data="currently working"
#return json.dumps(fetch_specific_data(type,name,i_num))
req_data=request.get_json()
return json.dumps(json.dumps(req_data))
if __name__=="__main__":
app.run()
I am getting a null
please help
This question already has answers here:
Get the data received in a Flask request
(23 answers)
Closed 5 years ago.
I can't figure this one out, it's not in the request.JSON and the request.data is coming up as empty bytes in the debug. There appears to be a post but the data is disappearing? Is this a bug with Flask?
Here's a link to their documentation page that has a Django example: https://documentation.mailgun.com/en/latest/quickstart-receiving.html#supported-actions-for-routes
Figured this out: Clue was in the header
'Content-Type': 'application/x-www-form-urlencoded'
Flask automatically strips out form data into request.form leaving request.data and request.json empty:
#app.route("/test-mail/", methods=["POST"], strict_slashes=False)
def test_mail():
print(request.form)
return 'OK'