2017-03-29 26 views
1

我在GAE上有很多針對Python的應用程序,還有一些基於AngularJS。其他人工作正常,而AngularJS則用於正常工作。現在,我得到以下錯誤:GAE中的AngularJS應用程序獲取CORS錯誤

XMLHttpRequest cannot load xxxxxxxxx/rest/loadlocale?locale=en. Redirect from 'xxxxxxxxxxxxx/rest/loadlocale?locale=en' to ' https://www.google.com/accounts/ServiceLogin?service=ah&passive=true& ...... has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'xxxxxxxx' is therefore not allowed access.

如果我去ServiceLogin明確從Chrome中,該應用程序將工作確定了一會兒。過了一段時間(我假設登錄到期時)錯誤再次出現。

app.yaml中具有以下部分:

- url: /rest/.* 
    script: main.APP 
    login: required 
    secure: always 

但刪除 「secure: always」 沒什麼區別。

該錯誤發生在第一個客戶端http請求,但請求處理程序的Python服務器代碼顯示沒有被訪問過的標誌爲 。

回答

1

出現這種情況的原因是您的app.yaml中的login: required表示所有XMLHttpRequest請求都需要有效的會話。

GAE的login由Google帳戶處理。所以你不能改變你的設置。

嘗試從app.yaml中刪除login。如果您只希望在沒有有效的Google會話的情況下允許某些請求,則需要指定允許和不允許的內容。例如:

- url: /rest/loadlocale 
    script: main.APP 
    login: optional # this is the default value and can be removed. 
    secure: always 

- url: /rest/.* 
    script: main.APP 
    login: required 
    secure: always 
+0

對不起,沒有這樣做。同樣的錯誤。我注意到其他可以正常工作的應用程序有時也有302(重定向)響應代碼。所以其他事情正在發生。難道這是因爲它起源於XXXX.appspot.com/rest而不是XXXX.appspot.com,它會觸發CORS錯誤? –

相關問題