小编Nic*_*ens的帖子

CherryPy访问控制允许来源

我在树莓派上安装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.
Run Code Online (Sandbox Code Playgroud)

我的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())
Run Code Online (Sandbox Code Playgroud)

如何使用CherryPy更改标头响应?

预先感谢=)

python ajax cherrypy

0
推荐指数
1
解决办法
1648
查看次数

标签 统计

ajax ×1

cherrypy ×1

python ×1