import requests
url = "https://nextdoor.com/login/?ucl=1"
username = "myusename"
password = "password"
response = requests.get(url, auth=(username, password), verify=False)
How should I post to my next door account using requests?
Log in requests use the "POST" method, not the "GET" method. Use requests.post instead of requests.get
r = requests.post('https://httpbin.org/post', data = {'key':'value'})
You can find syntax for this method in documentation.
https://requests.readthedocs.io/en/master/user/quickstart/
For what you're trying to do please consider using selenium, I've had to do similar things in the past and I found it easier.
Related
I've been trying to login into this website https://app.drillinginfo.com/gallery/ using Python and requests but I can't manage the session. I can't use Selenium, so I need a method in requests or urllib. Can anyone help me?
Here's the code I used before:
import requests
r = requests.Session()
payload = {'username':'password'}
r.post('https://app.drillinginfo.com/gallery/', data = payload)
data = r.get('https://app.drillinginfo.com/gallery/').text
Unfortunately, It doesn't log me in.
You need to pass in an actual username and password.
payload = {'username': 'YOURUSERNAME', 'password': 'YOURPASSWORD'}
url = 'https://app.drillinginfo.com/gallery/'
requests.post(url, data=payload)
you should use r.auth = ('user', 'password') or you should log in through their API if they've provided it
I am trying to login to the following web address: http://healthifyme.com/login/
using requests. I intend to scrap data from http://healthifyme.com/dashboard after login.
I am using following code to login using my registered credentials but login is not successful:
import requests, lxml.html
from lxml import html
url = 'http://healthifyme.com/login/'
s = requests.Session()
payload = {
'email': 'myemail#gmail.com',
'password': 'mypassword'
}
r = s.post(url, data=payload)
What I may be missing that's preventing the login attempt?
After 1 login attempt on the linked site, I noticed that the username and password are posted in a JSON object, instead of a form-like encoding like in the OP. Luckily that is excessibely simple with requests. You should simply use the json param to .post():
r = s.post(url, json=payload)
I'm trying to configure an Access Point(AP) in my office through HTTP Post method via Python.
I was able to login to the AP through Python HTTP Authentication code but when I click on wireless page of the AP to give inputs such as AP SSID, Channel and Passphrase, I'm getting stuck at this point. There is a apply button at the end of the wireless page.
When I'm trying to do that using the below mentioned code, I don't see any changes getting reflected at the AP side. May be my code is wrong or I'm not following the correct procedure to post the data in the AP. How can I resolve this issue?
import urllib2
import requests
def login():
link = "http://192.168.1.11/start_apply2.htm"
username = 'admin'
password = 'admin'
p = urllib2.HTTPPasswordMgrWithDefaultRealm()
p.add_password(None, link, username, password)
handler = urllib2.HTTPBasicAuthHandler(p)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
age = urllib2.urlopen(link).read()
payload = {'wl_ssid_org': 'nick','wl_wpa_psk_org':12345678}
r = requests.get(link)
r = requests.get(link, params=payload)
r = requests.post(link, params=payload)
login()
Note: When I'm running this code, it was throwing error as: 401 unauthorized. When I'm able to login to the AP using same auth code but why I'm unable to clear the authentication here, I'm not getting it.
In your case, you should change
r = requests.post(link, params=payload)
to
r = requests.post(link, data=payload)
Then you can do the POST request successfully.
You should refer to the requests document to find more tutorials.
Even, you can replace the code using urllib2 with code using requests.
I am trying to log in with a post request using the python requests module on a MediaWiki page:
import requests
s = requests.Session()
s.auth = ('....', '....')
url = '.....'
values = {'wpName' : '....',
'wpPassword' : '.....'}
req = s.post(url, values)
print(req.content)
I can't tell from the return value of the post request whether the login attempt was succesful. Is there something I can do to check this? Thanks.
Under normal circumstances i would advise you to go the mechanize way and make things way too easy for yourself but since you insist on requests, then let us use that.
YOu obviously have got the values right but i personally don't use the auth() function. So, try this instead.
import requests
url = 'https://example.com/wiki/index.php?title=Special:UserLogin'
values = {
'wpName': 'myc00lusername',
'wpPassword': 'Myl33tPassw0rd12'
}
session = requests.session()
r = session.post(url, data=values)
print r.cookies
This is what I used to solve this.
After getting a successful login, I read the texts from
response.text
and compared it to the text I got when submitting incorrect information.
The reason I did this is that validation is done on the server side and Requests will get a 200 OK response whether it was successful or not.
So I ended up adding this line.
logged_in = True if("Incorrect Email or password" in session.text) else False
Typically such an authentication mechanism is implemented using HTTP cookies. You might be able to check for the existence of a session cookie after you've authenticated successfully. You find the cookie in the HTTP response header or the sessions cookie attribute s.cookies.
I am pretty new to using urllib and requests module in python. I am trying to access a wikipage in my company's website which requires me to provide my login credentials through a pop up window when I try to access it through a browser.
I was able to write the following script to successfully access the webpage and read it using the following piece of code:
import sys
import urllib.parse
import urllib.request
import getpass
import http.cookiejar
wiki_page = 'http://wiki.company.com/wiki_page'
top_level_url = 'http://login.company.com/'
username = input("Enter Username: ")
password = getpass.getpass('Enter Password: ')
# Authenticate with login server and fetch the wiki page
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
cj = http.cookiejar.CookieJar()
password_mgr.add_password(None, top_level_url, username, password)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj),handler)
opener.open(wiki_page)
urllib.request.install_opener(opener)
with urllib.request.urlopen(wiki_page) as response:
# Do something
But now I need to use requests module to do the same. I tried using several methods including sessions but could not get it to work. The following is the piece of code which I think close to the actual solution but it gives Response 200 in the first print and Response 401 in the second print:
s = requests.Session()
print(s.post('http://login.company.com/', auth=(username, password))) # I have tried s.post() as well as s.get() in this line
print(s.get('http://wiki.company.com/wiki_page'))
The site uses the Basic Auth authorization scheme; you'll need to send the login credentials with each request.
Set the Session.auth attribute to a tuple with the username and password on the session:
s = requests.Session()
s.auth = (username, password)
response = s.get('http://wiki.company.com/wiki_page')
print(response.text)
The urllib.request.HTTPPasswordMgrWithDefaultRealm() object would normally only respond to challenges on URLs that start with http://login.company.com/ (so any deeper path will do too), and not send the password elsewhere.
If the simple approach (setting Session.auth) doesn't work, you'll need to find out what response is returned by accessing http://wiki.company.com/wiki_page directly, which is what your original code does. If the server redirects you to a login page, where you then use the Basic Auth information, you can replicate that:
s = requests.Session()
response = s.get('http://wiki.company.com/wiki_page', allow_redirects=False)
if response.status_code in (302, 303):
target = response.headers['location']
authenticated = s.get(target, auth=(username, password))
# continue on to the wiki again
response = s.get('http://wiki.company.com/wiki_page')
You'll have to investigate carefully what responses you get from the server. Open up an interactive console and see what responses you get back. Look at response.status_code and response.headers and response.text for hints. If you leave allow_redirects to the default True, look at response.history to see if there were any intermediate redirections.