#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13

    Htmldata = htmldata % (quote, music


    Code:
    A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
    
     /home/nikos/public_html/cgi-bin/metrites.py in ()
        208                 f = open( "/home/nikos/www/" + page, 'rb' )
        209                 htmldata = f.read()
    =>  210                 htmldata = htmldata % (quote, music)
        211                 
        212                 counter = ''' <center>
    htmldata = b'<!DOCTYPE html>\n<HTML>\n<TITLE>\xce\x9a\xce\x...ixel.gif" width="1" height="1">\n</form><br><br>', quote = b'\xce\x86\xce\xbd\xce\xb8\xcf\x81\xcf\x89\xcf\x...ce\xaf\xcf\x84\xce\xb5 \xce\xb5\xce\xb4\xcf\x8e.', music = 'Aha - Just Died In Your Arms.mp3'
    TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple' 
          args = ("unsupported operand type(s) for %: 'bytes' and 'tuple'",) 
          with_traceback = <built-in method with_traceback of TypeError object>
    This line htmldata = htmldata % (quote, music

    worked ok in 2.6. why not in 3.2.3?

    you cna see it at http://superhost.gr
    What is now proved was once only imagined!
  2. #2
  3. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    when i chaged the open to the following
    Code:
    		f = open( "/home/nikos/www/" + page, encoding="utf-8" )
    i get no error now, but now http://superhost.gr is blank page!
    What is now proved was once only imagined!
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    when i chaged the open to the following
    Code:
    		f = open( "/home/nikos/www/" + page, encoding="utf-8" )
    i get no error now, but now http://superhost.gr is blank page witohut producing an error.

    Any idea why?
    What should i check?
    What is now proved was once only imagined!
  6. #4
  7. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    any ides fellows?
    What is now proved was once only imagined!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by Nik
    Code:
    A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
    
     /home/nikos/public_html/cgi-bin/metrites.py in ()
        208                 f = open( "/home/nikos/www/" + page, 'rb' )
        209                 htmldata = f.read()
    =>  210                 htmldata = htmldata % (quote, music)
        211                 
        212                 counter = ''' <center>
    htmldata = b'<!DOCTYPE html>\n<HTML>\n<TITLE>\xce\x9a\xce\x...ixel.gif" width="1" height="1">\n</form><br><br>', quote = b'\xce\x86\xce\xbd\xce\xb8\xcf\x81\xcf\x89\xcf\x...ce\xaf\xcf\x84\xce\xb5 \xce\xb5\xce\xb4\xcf\x8e.', music = 'Aha - Just Died In Your Arms.mp3'
    TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple' 
          args = ("unsupported operand type(s) for %: 'bytes' and 'tuple'",) 
          with_traceback = <built-in method with_traceback of TypeError object>
    This line htmldata = htmldata % (quote, music

    worked ok in 2.6. why not in 3.2.3?

    you cna see it at http://superhost.gr
    Because in python 3, if you open a file as binary and then read from it, you will get a result of class 'bytes'. In python 2, you got a string.

    Why are you opening an ascii file as binary?

    See this example:

    Code:
    # file 'a' contains 'aaa'
    
    # python 2
    Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> data = open('a', 'rb').read()
    >>> data
    'aaa\n'
    
    # python 3
    Python 3.2.3 (default, Oct 19 2012, 20:10:41) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> data = open('a', 'rb').read()
    >>> data
    b'aaa\n'
    >>> type(data)
    <class 'bytes'>
  10. #6
  11. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    You are right i was openign it as binary

    i should have uses this instead:

    f = open( "/home/nikos/www/" + page, encoding="utf-8" )
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo