Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用请求登录网站_Python_Python 3.x_Python Requests - Fatal编程技术网

Python 使用请求登录网站

Python 使用请求登录网站,python,python-3.x,python-requests,Python,Python 3.x,Python Requests,我需要登录一个有请求的网站,但我所有的尝试都无效: from bs4 import BeautifulSoup as bs import requests s = requests.session() url = 'https://www.ent-place.fr/CookieAuth.dll?GetLogon?curl=Z2F&reason=0&formdir=5' def authenticate(): headers = {'username': 'myuser

我需要登录一个有请求的网站,但我所有的尝试都无效:

from bs4 import BeautifulSoup as bs
import requests
s = requests.session()
url = 'https://www.ent-place.fr/CookieAuth.dll?GetLogon?curl=Z2F&reason=0&formdir=5'


def authenticate():
    headers = {'username': 'myuser', 'password': 'mypasss', '_Id': 'submit'}
    page = s.get(url)
    soup = bs(page.content)
    value = soup.form.find_all('input')[2]['value']
    headers.update({'value_name':value})
    auth = s.post(url, params=headers, cookies=page.cookies)

authenticate()
或:

当我尝试使用.status_代码时,它返回200,但我希望使用401或403来执行类似“if login”的脚本

我发现了这一点,但我认为它在Python2中有效,但我使用Python3,我不知道如何转换…:

import requests
import sys

payload = {
    'username': 'sopier',
    'password': 'somepassword'
}

with requests.Session(config={'verbose': sys.stderr}) as c:
    c.post('http://m.kaskus.co.id/user/login', data=payload)
    r = c.get('http://m.kaskus.co/id/myform')
    print 'sopier' in r.content
有人知道怎么做吗

import requests
import sys

payload = {
    'username': 'sopier',
    'password': 'somepassword'
}

with requests.Session(config={'verbose': sys.stderr}) as c:
    c.post('http://m.kaskus.co.id/user/login', data=payload)
    r = c.get('http://m.kaskus.co/id/myform')
    print 'sopier' in r.content