Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'parameters': 0.04; 'api.': 0.05; 'subject:Python': 0.06; 'session.': 0.07; 'utf-8': 0.07; 'correct,': 0.09; 'subject:script': 0.09; 'cc:addr:python-list': 0.11; 'record,': 0.16; 'subject:login': 0.16; 'work.)': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'feb': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'login': 0.25; '(for': 0.26; 'code:': 0.26; 'asking': 0.27; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'related': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'requests': 0.31; 'coded': 0.31; 'though.': 0.31; 'username': 0.31; 'sense': 0.34; 'there,': 0.34; 'received:google.com': 0.35; 'server': 0.38; 'pm,': 0.38; 'logged': 0.60; 'from:charset:utf-8': 0.61; 'simply': 0.61; 'real': 0.63; 'decided': 0.64; 'skip:\xe2 10': 0.65; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'request.': 0.70; '8bit%:43': 0.74; 'leo': 0.84; 'phpbb': 0.84; 'url:mode': 0.84; 'url:php': 0.85; 'url:login': 0.93; 'url:tk': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=0IwXKh4b2po3oddhgxZQiP9uTF+mditUgoBXm9q5I9k=; b=ifSvk1UfCPVXMasfTKtRYDrBz0zbKzz1huasQDS7aBhmJ8qiwjmQk5LBbzwEXBTAJG QoBXx+v5OeYuKJUPs6WXfSqqSuVJnYDwanXSb2+YfxovdkuHA9UUFtKFQaeTFQIefpBM z+XwpEKV2clIytzYuMND3XU5KgZLlKj2DjoZscJHRi8yAZ3XjbGqz1c6Xidtuq9tEVm/ alU1on1v5MmiJg+CAtrDmPwqX8JF6GE4LtC90uQJEac+kUC0W48OrTcjQlS5h1cveIqM QLFUZPTD4RZ8sx00qxD1TUemmgaRBLc7Yy3EaRr8Tfm2e81Kpo+SN232Xr0wIAZKa6l7 Nogw== MIME-Version: 1.0 X-Received: by 10.53.8.166 with SMTP id dl6mr175188vdd.60.1392810601834; Wed, 19 Feb 2014 03:50:01 -0800 (PST) In-Reply-To: References: Date: Wed, 19 Feb 2014 12:50:01 +0100 Subject: Re: Python Requests script to login to a phpbb forum From: =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= To: Leo Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392810604 news.xs4all.nl 2872 [2001:888:2000:d::a6]:43057 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66684 On Wed, Feb 19, 2014 at 12:46 PM, Leo wrote: > Hi there, > > I have decided to jump in at the deep end to try and learn python. I have > been able to get requests to pull the login page off the server and I thi= nk > send the login request. I don't get logged in though. Please let me know = if > I would be better off asking in a phpBB related group or forum. > Here is my code without username and password included: You need cookies. In order to do it, simply use sessions instead of the =E2=80=9Cglobal=E2=80=9D API. Code: import requests payload =3D {'username': 'username', 'password': 'password'} session =3D requests.Session() r =3D session.post("http://www.tt-forums.net/ucp.php?mode=3Dlogin",data=3Dp= ayload) sidStart =3D r.text.find("sid")+4 sid =3D r.text[sidStart:sidStart+32] parameters =3D {'mode': 'login', 'sid': sid} r =3D session.post("http://www.tt-forums.net/ucp.php",params=3Dparameters,d= ata=3Dpayload) if "Logout" in r.text: print("We are in") (for the record, I added the session creation line and replaced requests. with session. so it uses your session. This code was not tested on a real phpBB forum; if everything you coded is correct, it will work.) --=20 Chris =E2=80=9CKwpolska=E2=80=9D Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense