我的代码在本地运行良好,但我使用的网络主机出现 500 错误。问题似乎来自线路
js = json.load(data)
在搜索方法中。我缺少cherrypy配置中的某些内容吗?有什么想法吗?
#!/usr/local/bin/python3.2
import cherrypy
import json
import numpy as np
from urllib.request import urlopen
class Root(object):
@cherrypy.expose
def index(self):
a_query = Query()
text = a_query.search()
return '''<html>
Welcome to Spoti.py! %s
</html>''' %text
class Query():
def __init__(self):
self.qstring = '''if i can't'''
def space_to_plus(self):
self.qstring = self.qstring.replace(' ', '+')
def search(self):
self.space_to_plus()
url = 'http://ws.spotify.com/search/1/track.json?q=' + self.qstring
data = urlopen(url)
js = json.load(data)
return self.qstring
cherrypy.config.update({
'environment': 'production',
'log.screen': False,
'server.socket_host': '127.0.0.1',
'server.socket_port': 15083,
})
cherrypy.config.update({'tools.sessions.on': True})
cherrypy.quickstart(Root())