我的覆盆子上的CherryPy安装有问题。
当我用ajax请求CherryPy的功能时,我有这样的信息:
XMLHttpRequest cannot load http://my_ip:8888/takePicture. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my_ip' is therefore not allowed access.
我的python代码:
import time
import os
import cherrypy
class Camera(object):
@cherrypy.expose
def takePicture(self):
os.system('fswebcam -r 1280x720 -S 3 --info Salon --jpeg 100 --save images/history/%H%M%S.jpg')
os.system('fswebcam -r 1280x720 -S 3 --info Salon --jpeg 100 --save images/last.jpg')
if __name__ == '__main__':
cherrypy.config.update({'server.socket_host': 'my_ip'})
cherrypy.config.update({'server.socket_port': 8888})
cherrypy.quickstart(Camera())
如何使用CherryPy更改标头响应?
感谢advance =)
答案 0 :(得分:4)
尝试将您的启动更改为:
if __name__ == '__main__':
conf = {
'/': {
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'image/jpeg'), ('Access-Control-Allow-Origin', 'http://my_ip')],
'server.socket_host': 'my_ip',
'server.socket_port': 8888
}
}
cherrypy.quickstart(Camera(), '/', conf)