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

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

    Question Changing filenames from Greeklish => Greek (subprocess complain)


    Code:
     /home/nikos/public_html/cgi-bin/metrites.py in () 
        217                 template = htmldata + counter 
        218         elif page.endswith('.py'): 
    =>  219                 htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + page ) 
        220                 template = htmldata.decode('utf-8').replace( 'Content-type: text/html; charset=utf-8', '' ) + counter 
        221                 
    htmldata undefined, subprocess = <module 'subprocess' from '/opt/python3/lib/python3.3/subprocess.py'>, subprocess.check_output = <function check_output>, page = 'files.py' 
     /opt/python3/lib/python3.3/subprocess.py in check_output(timeout=None, *popenargs=('/home/nikos/public_html/cgi-bin/files.py',), **kwargs={}) 
        584         retcode = process.poll() 
        585         if retcode: 
    =>  586             raise CalledProcessError(retcode, process.args, output=output) 
        587     return output 
        588 
    global CalledProcessError = <class 'subprocess.CalledProcessError'>, retcode = 1, process = <subprocess.Popen object>, process.args = '/home/nikos/public_html/cgi-bin/files.py', output = b'Content-type: text/html; charset=utf-8\n\n<bod...n position 74: surrogates not allowed\n\n-->\n\n' 
    CalledProcessError: Command '/home/nikos/public_html/cgi-bin/files.py' returned non-zero exit status 1 
          args = (1, '/home/nikos/public_html/cgi-bin/files.py') 
          cmd = '/home/nikos/public_html/cgi-bin/files.py' 
          output = b'Content-type: text/html; charset=utf-8\n\n<bod...n position 74: surrogates not allowed\n\n-->\n\n' 
          returncode = 1 
          with_traceback = <built-in method with_traceback of CalledProcessError object>

    The above error message happened when i tried to reanme one of my filenames from

    its greeklish name to greek charcters.

    files.py is a script that allows users to downlaod fiels form my server.
    But i wish to present filenames in Greek and not in Greeklish

    http://superhost.gr/?page=files.py
    as it is now.

    What can i do to make pth script accept greek filenames too?
    Why does subprocess is complaining?
    What is now proved was once only imagined!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    Maybe some of the comments in this issue are relevant?
    http://bugs.python.org/issue13717
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,283
    Rep Power
    13
    Here is the relevent code:

    Code:
    	for row in data:
    		(url, hits, host, lastvisit) = row
    		shorturl = url.decode('utf-8').replace( '/home/nikos/www/data/apps/', '' )
    		lastvisit = lastvisit.strftime('%A %e %b, %H:%M')
    		
    		print('''
    		<form method="get" action="cgi-bin/files.py">
    			<tr>
    				<td> <center> <input type="submit" name="shorturl" value="%s"> </td>
    				<td> <center> <font color=yellow size=5> %s </td>
    				<td> <center> <font color=orange size=4> %s </td>
    				<td> <center> <font color=silver size=4> %s </td>
    			</tr>
    		</form>
    		''' % (shorturl, hits, host, lastvisit) )
    I switched

    shorturl = url.replace( '/home/nikos/www/data/apps/', '' )

    with

    shorturl = url.decode('utf-8').replace( '/home/nikos/www/data/apps/', '' )

    bu still im presenting with the same error.
    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,283
    Rep Power
    13
    or does this need some kind of encoding decoding to work properly?

    Code:
    htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + page )
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo