Skip to main content
 首页 » 编程设计

python之来自源 'https://storage.googleapis.com' 的字体已被跨源资源共享策略阻止加载

2025年05月04日34lidabo

背景

  • 我正在使用 Flask 使用 Python 运行 Google App Engine。
  • 我正在通过 https://storage.googleapis.com/ 调用 Google Cloud Storage 存储桶中的某些网络 Assets *

根据以下证据,我可以验证请求中是否设置了 Access-Control-Allow-Origin header 。

问题

为什么我的浏览器(chrome)仍然出现以下错误。

Font from origin 'https://storage.googleapis.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

代码

我正在使用 Flask Snippet “HTTP 访问控制装饰器”,设置来源如下:

@admin_articles_routes.route('/xxx/xxx/xxx-xx') 
@crossdomain(origin="*") 
@authenticate_admin 
def edit_article(): 

-------- 编辑------------

Curl response 
Vinays-MacBook-Pro:App-Engine vinay$ curl -version http://localhost:8080/xxxx/xxxx/xxxx-xxxx?ID=ahlkZXZ-Y2ZjLW1lbGJvdXJuZS13ZWJzaXRlcjbGUYgICAgICAgAoM 
*   Trying ::1... 
* connect to ::1 port 8080 failed: Connection refused 
*   Trying 127.0.0.1... 
* Connected to localhost (127.0.0.1) port 8080 (#0) 
> GET /xxx/xxxx/xxxx-xxxxx?ID=ahlkZXZ-Y2ZjLW1lbGJvdXJuZS13ZWJzaXRlcjELEgdBcnRpY2xlIhBBcnRpY2xlR3JhZHBhS2V5DAsSB0FydGljbGUYgICAgICAgAoM HTTP/1.1 
> Host: localhost:8080 
> User-Agent: curl/7.43.0 
> Accept: */* 
> Referer: rsion 
>  
< HTTP/1.1 302 Found 
< access-control-max-age: 21600 
< location: http://localhost:8080/_ah/login?continue=http%3A//localhost%3A8080/xxxx/xxxxx/xxxx-xxxxx%3FID%3DahlkZXZ-Y2ZjLW1lbGJvdXJuZS13ZWJzbGUYgICAgICAgAoM 
< access-control-allow-origin: * 
< access-control-allow-methods: HEAD, GET 
< content-type: text/html; charset=utf-8 
< Cache-Control: no-cache 
< Expires: Fri, 01 Jan 1990 00:00:00 GMT 
< Content-Length: 575 
< Server: Development/2.0 

请您参考如下方法:

这是一个 Community Wiki post Greg 提供的最后一个答案。

CORS Access-Control-Allow-Origin header 应由接受请求的主机服务器返回,因为它是服务器设置谁可以访问其自己的资源的规则。

CORS OPTIONS preflight headers由发出请求的请求者设置,以便它正确地向主机服务器标识自己。

有关更多信息,您可以查看此附加 Stack Overflow post .