raise UnicodeError, "label too long"

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

    #1

    raise UnicodeError, "label too long"

    Hi I am havin a problem with urllib2.urlopen .

    I get this error when I try to pass a unicode to it.

    raise UnicodeError, "label too long"

    is this problem avoidable? no browser or programs such as wget seem to
    have a problem with these strings.

  • Marc 'BlackJack' Rintsch

    #2
    Re: raise UnicodeError, "label too long"

    In <1169672223.231 030.262610@l53g 2000cwa.googleg roups.com>, Flavio wrote:
    Hi I am havin a problem with urllib2.urlopen .
    >
    I get this error when I try to pass a unicode to it.
    >
    raise UnicodeError, "label too long"
    >
    is this problem avoidable? no browser or programs such as wget seem to
    have a problem with these strings.
    What exactly are you doing? How does a (unicode?) string look like that
    triggers this exception?

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Flavio

      #3
      Re: raise UnicodeError, &quot;label too long&quot;

      What I am doing is very simple:

      I fetch an url (html page) parse it using BeautifulSoup, extract the
      links and try to open each of the links, repeating the cycle.

      Beautiful soup converts the html to unicode. That's why when I try to
      open the links extracted from the page I get this error.

      This is bad, since some links do contain strings with non-ascii
      characters.

      thanks,

      Flávio


      Marc 'BlackJack' Rintsch escreveu:
      In <1169672223.231 030.262610@l53g 2000cwa.googleg roups.com>, Flavio wrote:
      >
      Hi I am havin a problem with urllib2.urlopen .

      I get this error when I try to pass a unicode to it.

      raise UnicodeError, "label too long"

      is this problem avoidable? no browser or programs such as wget seem to
      have a problem with these strings.
      >
      What exactly are you doing? How does a (unicode?) string look like that
      triggers this exception?

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

        #4
        Re: raise UnicodeError, &quot;label too long&quot;

        Flavio schrieb:
        What I am doing is very simple:
        >
        I fetch an url (html page) parse it using BeautifulSoup, extract the
        links and try to open each of the links, repeating the cycle.
        >
        Beautiful soup converts the html to unicode. That's why when I try to
        open the links extracted from the page I get this error.
        >
        This is bad, since some links do contain strings with non-ascii
        characters.
        Please try answering the exact question that Marc asked:
        what is an example for unicode string that triggers the
        exception?

        Regards,
        Martin

        Comment

        • Flavio

          #5
          Re: raise UnicodeError, &quot;label too long&quot;


          something like this, for instance:
          http://.wikipedia.org/wiki/Copper%28II%29_hydroxide

          but even url with any non-ascii characters such as this

          http://.wikipedia.org/wiki/Ammonia

          also fail when passed to urlopen :
          File "/usr/lib/python2.4/encodings/idna.py", line 72, in ToASCII
          raise UnicodeError, "label too long"
          UnicodeError: label too long

          very strange, because I tried other unicode urls from the python
          console like this

          urllib2.urlopen (u'www.google.c om')

          and it works normally:





          Martin v. Löwis escreveu:
          Flavio schrieb:
          What I am doing is very simple:

          I fetch an url (html page) parse it using BeautifulSoup, extract the
          links and try to open each of the links, repeating the cycle.

          Beautiful soup converts the html to unicode. That's why when I try to
          open the links extracted from the page I get this error.

          This is bad, since some links do contain strings with non-ascii
          characters.
          >
          Please try answering the exact question that Marc asked:
          what is an example for unicode string that triggers the
          exception?

          Regards,
          Martin

          Comment

          • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

            #6
            Re: raise UnicodeError, &quot;label too long&quot;

            Flavio schrieb:
            something like this, for instance:
            http://.wikipedia.org/wiki/Copper%28II%29_hydroxide
            >
            but even url with any non-ascii characters such as this
            >
            http://.wikipedia.org/wiki/Ammonia
            >
            also fail when passed to urlopen :
            File "/usr/lib/python2.4/encodings/idna.py", line 72, in ToASCII
            raise UnicodeError, "label too long"
            UnicodeError: label too long
            >
            very strange, because I tried other unicode urls from the python
            console like this
            It's the host name that starts with a dot that makes it fails:

            pyu".wikipedia. org".encode("id na")
            Traceback (most recent call last):
            File "<stdin>", line 1, in ?
            File "encodings/idna.py", line 163, in encode
            File "encodings/idna.py", line 72, in ToASCII
            UnicodeError: label too long
            pyu"wikipedia.o rg".encode("idn a")
            'wikipedia.org'

            The exception is certainly misleading; I'll have to find out
            whether there is a bug beyond that (i.e. whether host names
            with empty labels should be accepted).

            Regards,
            martin

            Comment

            • Flavio

              #7
              Re: raise UnicodeError, &quot;label too long&quot;

              Guys, I am sorry I wrote these messages very late at night.

              Naturally what came before the dot is the language defining two letter
              string that is usual of wikipedia urls.

              Something in my code is obviously gobbling that up. Thanks for pointing
              that out and my apologies again for not seeing this obvious bug.



              On Jan 25, 4:39 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
              On 24 Jan 2007 16:25:19 -0800, "Flavio" <fccoe...@gmail .comdeclaimed
              the following in comp.lang.pytho n:
              >
              >
              >
              something like this, for instance:
              http://.wikipedia.org/wiki/Copper%28II%29_hydroxide Was there some text between the // and .wikipedia? As written this,
              and the next one, both lock up Firefox. Take out the . and they work (or
              put www before the . ).
              >
              --
              Wulfraed Dennis Lee Bieber KD6MOG
              wlfr...@ix.netc om.com wulfr...@bestia ria.com

              (Bestiaria Support Staff: web-a...@bestiaria. com)
              HTTP://www.bestiaria.com/

              Comment

              Working...