Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'urllib2': 0.07; 'wednesday,': 0.07; 'function,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'missed': 0.12; 'loops': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; '31,': 0.24; 'password.': 0.24; 'file.': 0.24; 'login': 0.25; 'script': 0.25; 'post': 0.26; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'moved': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'subject:website': 0.31; 'username': 0.31; 'open': 0.33; 'problem': 0.35; 'created': 0.35; 'skip:u 20': 0.35; 'done.': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'should': 0.36; 'two': 0.37; 'level': 0.37; 'to:addr:python- list': 0.38; 'rather': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'users': 0.40; 'even': 0.60; 'act': 0.63; 'email addr:gmail.com': 0.63; 'name': 0.63; 'july': 0.63; 'statement,': 0.68; 'login.': 0.93; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: script to Login a website Date: Thu, 1 Aug 2013 14:18:40 +0000 (UTC) References: <6ad4bcae-40ba-4fd1-9b88-f0072cc17764@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.29 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) 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: 71 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375366743 news.xs4all.nl 15988 [2001:888:2000:d::a6]:52009 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51735 wachkama@gmail.com wrote: > On Wednesday, July 31, 2013 11:33:25 AM UTC-4, wach...@gmail.com wrote: >> I have created a script to log in a website. It gets its username and password from two files, then log's in with this credentials. My code is not showing me what username it is using to login from the file. And I am not sure if it is even opening up the url and prompting for login. I am stuck can someone help me ? >> >> >> >> >> >> >> >> >> >> >> >> import urllib, urllib2 >> >> >> >> user = open ('users.txt' , 'r') >> >> password = open ('password.txt' , 'r') >> >> >> >> for users in user: >> >> password.seek(0) >> >> for pass_list in password: >> >> login_data = users + '\n' + pass_list >> >> print login_data Please ignore myearlier post, as I somehow missed your post where you showed the code. Anyway, your problem is that you print the login_data, but you don't act on it. You should make the call to the login function right after the print statement, rather than after the loops are done. At that point, all you have is the last user name and password. All the following code should be moved to a function, and called from the same level as the print. >> >> >> >> base_url = 'http://mysite.com' >> >> #login action we want to post data to >> >> response = urllib2.Request(base_url) >> >> login_action = '/auth/login' >> >> login_action = base_url + login_action >> >> response = urllib2.urlopen(login_action, login_data) >> >> response.read() >> >> print response.headers >> >> print response.getcode() > = -- DaveA