我之前问过一个类似的问题,但我终于在解决它方面取得了进一步的进展,但现在我被卡住了。
我在 Dreamhost 的网络服务器上运行 python。我使用 putty 进入它并运行我的 python 脚本,它工作得很好。但是当我使用 exec 从 php 运行它时,它崩溃了。
在 php 中使用 passthru() 函数时,我会返回此错误:
Traceback (most recent call last): File "newwork.py", line 20,
in api=lastfm.Api(api_key) File "lastfm/api.py", line 22,
in __init__ File "lastfm/filecache.py", line 19,
in __init__ File "lastfm/filecache.py", line 76,
in _InitializeRootDirectory File "lastfm/filecache.py", line 70,
in _GetTmpCachePath File "lastfm/filecache.py", line 66,
in _GetUsername OSError: [Errno 22] Invalid argument
我不知道这意味着什么或我应该从哪里开始。有关更多信息,我正在使用此处找到的 python lastfm 模块:http ://code.google.com/p/python-lastfm/
我的python脚本只是这样做:
import sys
import lastfm
import MySQLdb
sys.stderr=sys.stdout
value="testuser"
api_key='---my api key is here'
api=lastfm.Api(api_key)
user=api.getUser(value)
top_artists=user.topArtists
任何帮助将不胜感激,或任何想法。我什至不知道从哪里开始。
编辑:我做了更多的工作,发现最后一行是:
line 66, in _GetUsername os.getlogin() or \ OSError: [Errno 22] Invalid argument
GetUsername 函数就是这样的:
def _GetUsername(self):
'''Attempt to find the username in a cross-platform fashion.'''
return os.getenv('USER') or \
os.getenv('LOGNAME') or \
os.getenv('USERNAME') or \
os.getlogin() or \
'nobody'
缩进不在这里更正。