1

i'm dealing with HTTPS and i want to get HTTP header for live.com

import urllib2

try:
    email="HelloWorld1234560@hotmail.com"
    response = urllib2.urlopen("https://signup.live.com/checkavail.aspx?chkavail="+email+"&tk=1258056184535&ru=http%3a%2f%2fmail.live.com%2f%3frru%3dinbox&wa=wsignin1.0&rpsnv=11&ct=1258055283&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1036&id=64855&bk=1258055288&rollrs=12&lic=1")
    print 'response headers: "%s"' % response.info()
except IOError, e:
    if hasattr(e, 'code'): # HTTPError
        print 'http error code: ', e.code
    elif hasattr(e, 'reason'): # URLError
        print "can't connect, reason: ", e.reason
    else:
        raise

so i don't want all the information from headers i just want Set-Cookie information

if you asking what is script do : it's for checking if email avilable to use in hotmail by get the amount from this viralbe CheckAvail=

after edit

thanks for help .. after fixing get only Set-Cookie i got problem it's when i get cookie not get CheckAvil= i got a lot information without `CheckAvil= after open it in browser and open the source i got it !! see the picture enter image description here

jack-X
  • 287
  • 5
  • 14
  • @senderle - I think the question is how to get a specific header from `response.info()` object. – AJ. Jun 21 '11 at 17:55

2 Answers2

5

The object returned by response.info() is an instance of mimetools.Message (as described by the urllib2 docs), which is a subclass of rfc822.Message, which has a getheader() method.

So you can do the following:

response = urllib2.urlopen("...")
print response.info().getheader("Set-Cookie") # get the value of the Set-Cookie header

However, if you are checking for mail, I would recommend you to use POP3 or IMAP if available (Python comes with modules for both).

Liquid_Fire
  • 6,990
  • 2
  • 25
  • 22
  • Liquid_Fire sir give me the idea for checking avilabe mails via `POP3` or `IMAP` it's look like great idea – jack-X Jun 21 '11 at 18:20
  • Have a look at the docs for the [`poplib`](http://docs.python.org/library/poplib.html) and [`imaplib`](http://docs.python.org/library/imaplib.html) modules (they both have examples near the bottom), and look in the Windows Live help for POP3 or IMAP configuration settings which will give you the server, port and other settings you'll need to provide to the library to connect. – Liquid_Fire Jun 21 '11 at 18:52
  • guys why the `CheckAvail=` not in the header !! i have code by perl and in the header i got `CheckAvail= ?!` – jack-X Jun 21 '11 at 21:28
0

It's because 'Httponly' in your http response, which meant, because of the specifications, only http connection can view.

Alan Dong
  • 3,981
  • 38
  • 35