Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'urllib2': 0.07; 'subject:script': 0.09; 'cc:addr:python-list': 0.11; 'loop.': 0.16; 'newline,': 0.16; 'simpler,': 0.16; 'stuff.': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; 'import': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; '31,': 0.24; 'documented': 0.24; 'file.': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'login': 0.25; 'script': 0.25; 'post': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'am,': 0.29; 'specified': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'easier': 0.31; 'requests': 0.31; "skip:' 10": 0.31; 'subject:website': 0.31; 'tuples': 0.31; 'username': 0.31; 'open': 0.33; 'url:python': 0.33; 'created': 0.35; 'skip:u 20': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'two': 0.37; 'url:library': 0.38; 'sure': 0.39; 'called': 0.40; 'users': 0.40; 'url:mail': 0.40; 'even': 0.60; 'to:addr:gmail.com': 0.65; 'jul': 0.74; 'understand,': 0.84; 'joel': 0.91; 'url:latest': 0.91; 'login.': 0.93; '2013': 0.98 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=q/XwTNnaKMyPXrWnpR5pIiPfoOQbd+0Xc8N0tooKMS8=; b=BjGs4YXI3FlJtKftdfhkv3HnjBrqeCKGur3N0wkAUUawh6ILvkYkY2Wx8lzjNDLqKn hb8N46f0IXylDbASJQgzMEocj/3r96CSMmPqXnp9A9RnxyaMltBS1kfXRnbpLD6RKwMj n1FDPqxuhP4jYf3Ju1vsbjNTzdNvFTLGuIjwjXyucoITJy1qEIGLQ8nB6VMmXHa4Ruf9 gksQvycuhZhVLxAFdH5J/iELbp1Ld8hUpbMVmyylWPSTiWq3CsGJ+pY+PmrlHaXTkRlv 4mgElO977PkIfRgCDMFXYyMDHeLjO2tvqKZ5u1eZTRWuZ7l2xJ6WCiZaZrFmOEYNL002 KKTA== MIME-Version: 1.0 X-Received: by 10.58.97.238 with SMTP id ed14mr21411848veb.34.1375303167537; Wed, 31 Jul 2013 13:39:27 -0700 (PDT) In-Reply-To: References: Date: Wed, 31 Jul 2013 16:39:27 -0400 Subject: Re: script to Login a website From: Joel Goldstick To: wachkama@gmail.com 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375303175 news.xs4all.nl 15892 [2001:888:2000:d::a6]:39836 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51705 On Wed, Jul 31, 2013 at 11:33 AM, wrote: > > I have created a script to log in a website. It gets its username and pas= sword from two files, then log's in with this credentials. My code is not s= howing me what username it is using to login from the file. And I am not su= re if it is even opening up the url and prompting for login. I am stuck can= someone help me ? > > > > > > import urllib, urllib2 > > user =3D open ('users.txt' , 'r') > password =3D open ('password.txt' , 'r') > > for users in user: > password.seek(0) > for pass_list in password: > login_data =3D users + '\n' + pass_list > print login_data > I think you will note that login_data is overwritten each password loop. In the end of all of the above you have the last users followed by a newline, followed by the last pass_list You might want to think about putting the code below in a function that can be called after print login_data above if you want to check each username and password combination. > base_url =3D 'http://mysite.com' > #login action we want to post data to > response =3D urllib2.Request(base_url) > login_action =3D '/auth/login' > login_action =3D base_url + login_action > response =3D urllib2.urlopen(login_action, login_data) I don't think the above line provides login_data as specified by the spec: http://docs.python.org/2/library/urllib2.html#module-urllib2 It looks like data needs to be tuples > response.read() > print response.headers > print response.getcode() > > -- Once you correct the top of your code I recommend Requests module since its easier to understand, simpler, and better documented than the standard url stuff. You can find it at http://docs.python-requests.org/en/latest/ > http://mail.python.org/mailman/listinfo/python-list --=20 Joel Goldstick http://joelgoldstick.com