special character in python script leading to exception

hello

I create a loop to get all links from my text files and the links with the special character causes an error.

The loop
f = open('adnvideo.txt', "r")
for line in f.readlines():
    subprocess.call(["python","adnplay.py", line])

Open in new window


the error

Seiya Tôdôin, 16 ans, beau, riche... mais célibataire - VOSTFR
Traceback (most recent call last):
  File "adnplay.py", line 36, in <module>
    f.write(s + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 77: ordinal not in range(128)

Open in new window


and i test this

import io
f = io.open('adnvideo.txt'r', encoding='ascii')

Open in new window

result
 File "start.py", line 48
   f = io.open('adnvideo.txt'r', encoding='ascii')
                                                             ^
SyntaxError: invalid syntax

Open in new window


code files  1
http://pastebin.com/hqJ9fzuw

code files 2
http://pastebin.com/VG6MbYwi

ty :)
aeko satoAsked:
Who is Participating?
 
Walter RitzelSenior Software EngineerCommented:
You can try replace the line that gives error on adnplay.py by this:
f.write(s.encode('utf-8') + '\n')

Open in new window

0
 
Walter RitzelSenior Software EngineerCommented:
Try to change the encoding to utf-8 instead of ascii.

f = open('adnvideo.txt', "r")
for line in f.readlines():
    subprocess.call(["python","adnplay.py", line.encode('utf-8')])

Open in new window

0
 
aeko satoAuthor Commented:
error
Traceback (most recent call last):
  File "start.py", line 50, in <module>
    subprocess.call(["python","adnplay.py", line.encode('utf-8')])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 73: ordinal not in range(128)

Open in new window


it is possible that the error comes from adnplay file (code files 1)
0
 
aeko satoAuthor Commented:
it works !!!! ty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.