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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aeko satoAuthor Commented:
it works !!!! ty
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.