swagger Fail to fetch
给公司写api接口,使用的是python+tornado+swagger。在swagger ui里execute时总是报错Fail to fetch
,找了几十分钟错,发现tornado接收的是http,https不行。改成了http,还是不行。
我以为是adb干的好事,把数据拦截了,关了adb也还是不行。又找了几个小时穷途末路之际终于通过浏览器F12得知是跨域问题。
def get(self, *args, **kwargs):
print('receive GET request...')
self.set_header("Access-Control-Allow-Origin", "*")
self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT')
self.set_header("Access-Control-Allow-Headers", "token, content-type, user-token")
在get里加了这3行,问题解决。
在此写下这篇笔记,以此为戒。