저는 파이썬 프로그램이 잘 돌아가고 있습니다. 여러 웹 사이트에 연결하여 원하는 정보를 출력합니다. 모든 웹 사이트가 utf-8로 인코딩 된 것은 아니므로 헤더에서 charset을 요청하고 디코드하기 위해 unicode(string, encoding)
메서드를 사용하고 있습니다. (이 방법은 적절한 방법인지 잘 모르지만 잘 작동합니다). 내가 python 프로그램을 실행할 때 나는 no ??? 자국 및 잘 작동합니다. 나는 PHP의 system
기능을 사용하여 프로그램을 실행할 때,이 오류가 나타납니다php system, python, utf-8
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0131' in position 41: ordinal not in range(128)
이것은 파이썬 특정 오류입니다하지만 나를 혼란은 내가 터미널을 사용하여 프로그램을 실행할 때이 오류가 없다는 것입니다 . 나는 PHP의 system
함수를 사용하고 php에서 프로그램을 호출 할 때만 이것을 받는다. 이 문제의 원인은 무엇일까요?
system("python somefile.py $search") // where $search is the variable coming from an input
파이썬 코드 :
encoding = "iso-8859-9"
l = "some string here with latin characters"
print unicode("<div class='line'>%s</div>" % l, encoding)
# when I run this code from terminal it works perfect and I receive no ??? marks
# when I run this code from php, I receive the error above
아마도 환경 변수 일 겁니다. –