how to check the 'content/type' using urlopen

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    how to check the 'content/type' using urlopen


    i have the following code to open a URL address, but can you please
    tell me how can I check the content type of the url response?

    Thank you.

    try:
    req = Request(url, txdata, txheaders)
    handle = urlopen(req)
    except IOError, e:
    print e
    print 'Failed to open %s' % url
    return 0;

    else:
    data = handle.read()

  • Michael Bentley

    #2
    Re: how to check the 'content/type' using urlopen


    On Apr 15, 2007, at 6:25 PM, John wrote:
    >
    i have the following code to open a URL address, but can you please
    tell me how can I check the content type of the url response?
    >
    Thank you.
    >
    try:
    req = Request(url, txdata, txheaders)
    handle = urlopen(req)
    except IOError, e:
    print e
    print 'Failed to open %s' % url
    return 0;
    >
    else:
    data = handle.read()
    Not absolutely sure about this, but try handle.headers. get('Content-
    Type') before the read.

    hth,
    Michael
    ---
    Asking a person who he *is* ... is not Pythonic! --Anton Vredegoor




    Comment

    • John J. Lee

      #3
      Re: how to check the 'content/type' using urlopen

      Michael Bentley <michael@jedimi ndworks.comwrit es:
      On Apr 15, 2007, at 6:25 PM, John wrote:
      >

      i have the following code to open a URL address, but can you please
      tell me how can I check the content type of the url response?

      Thank you.

      try:
      req = Request(url, txdata, txheaders)
      handle = urlopen(req)
      except IOError, e:
      print e
      print 'Failed to open %s' % url
      return 0;

      else:
      data = handle.read()
      >
      Not absolutely sure about this, but try handle.headers. get('Content-
      Type') before the read.
      handle.get_head er("Content-type")


      John

      Comment

      Working...