Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: 403 CORS error -tfhub/imagenet/mobilenet. Issue was last night, resolved this morning. Occurred again 3/26 1:47pm est #904

Closed
devihall03 opened this issue Mar 22, 2024 · 12 comments
Labels

Comments

@devihall03
Copy link

What happened?

Around 9pm yesterday had an issue with imagenet/mobilenet_v1_025_224/classification/1/model.json

Webapp made api call to
https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json

got redirected to
https://storage.googleapis.com/kagglesdsdata/models/1514/1807/model.json?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=gcp-kaggle-com%40kaggle-161607.iam.gserviceaccount.com%2F20240322%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20240322T025731Z&X-Goog-Expires=259200&X-Goog-SignedHeaders=host&X-Goog-Signature=032994d5e34eddcb4ba94f531ad298c332b7504d3f859395d160fd2088c5e6facad9cebddce7a9e112a1dacd2496bdbb73fbf5c3d63d8b814b8d90b7fceb864b0611dcf680b7b033347fd8a6260561a4576fb9d7c02a7da200f58b3e02ab7acae8d119efa5986fbd30b8fab0e7a383dafd7813aa6c791d9473733910341aad489dde24e6c5d3bab7139f3bde0abc6efa14811caa539b3e9b47be833102cf1d884c3c68268b9ec38332d81ff1a03803ed913ed70270f266b82eaa41bde697a1242f55648742ab33f4cf35bfa6d5e4a9c67c1b952fb3f6fa5d3c149a0bd6e6a5b83e3836b63d5b8dd7c779ffdee942e3bd6a17b5d7f86e19c0fed82bbde6e92650

Model did not load and console showed
error: Access to fetch at 'https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/1/model.json?tfjs-format=file' from origin 'http://127.0.0.1:5501' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'http://127.0.0.1:5500' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

IP address had not changed. Using the same device. One minute requesta and response was fine, next minute CORS error.

Relevant code

// Function to handle model loading
function modelReady() {
  console.log("Model is ready");
}

Relevant log output

error: Access to fetch at 'https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/1/model.json?tfjs-format=file' from origin 'http://127.0.0.1:5501' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'http://127.0.0.1:5500' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

tensorflow_hub Version

0.12.0 (latest stable release)

TensorFlow Version

2.8 (latest stable release)

Other libraries

ML5
P5
JQuery
Bootstrap

Python Version

3.x

OS

macOS

@KeijiBranshi
Copy link
Collaborator

Hi @devihall03, thanks for posting.

Do you mind reproducing and sharing the HTTP Request-Response headers associated with your failed requests to https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/1/model.json?tfjs-format=file?

Here are the instructions to find them on Chrome, but it may differ depending on your browser.

Thanks!

@devihall03
Copy link
Author

General:
Request URL:
https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/group43-shard1of1
Request Method:
GET
Status Code:
200 OK (from disk cache)
Remote Address:
[2607:f8b0:4002:c05::cf]:443
Referrer Policy:
strict-origin-when-cross-origin

Response Headers:
Accept-Ranges:
bytes
Access-Control-Allow-Origin:
*
Access-Control-Expose-Headers:
*, Content-Length, Date, Server, Transfer-Encoding, X-GUploader-UploadID, X-Google-Trace
Age:
0
Alt-Svc:
h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control:
public, max-age=3600
Content-Length:
512
Content-Type:
application/octet-stream
Date:
Tue, 26 Mar 2024 17:29:40 GMT
Etag:
"f98a7ecec81976b48509940e9a0ce366"
Expires:
Tue, 26 Mar 2024 18:29:40 GMT
Last-Modified:
Mon, 12 Mar 2018 18:28:21 GMT
Server:
UploadServer
X-Goog-Generation:
1520879301195712
X-Goog-Hash:
crc32c=NPQ3bw==, md5=+Yp+zsgZdrSFCZQOmgzjZg==
X-Goog-Metageneration:
2
X-Goog-Storage-Class:
MULTI_REGIONAL
X-Goog-Stored-Content-Encoding:
identity
X-Goog-Stored-Content-Length:
512
X-Guploader-Uploadid:
ABPtcPqW00WYCwiRgkjOmxeYVQnGDSuvEMLG3OevNGgFNhZHJHKkmB8bPyNH8050NcnYMDmNgFg3EFsL2A

Request Headers:
Referer:
http://127.0.0.1:5500/
Sec-Ch-Ua:
"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"
Sec-Ch-Ua-Mobile:
?0
Sec-Ch-Ua-Platform:
"macOS"
User-Agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

@devihall03
Copy link
Author

Screenshot 2024-03-26 at 1 43 02 PM

@devihall03
Copy link
Author

devihall03 commented Mar 26, 2024

@KeijiBranshi Just got this same error again just now. What is going on??? It was working one minute and now its not!

@devihall03 devihall03 changed the title Bug: 403 CORS error -tfhub/imagenet/mobilenet. Issue was last night, resolved this morning Bug: 403 CORS error -tfhub/imagenet/mobilenet. Issue was last night, resolved this morning. Occurred again 3/26 1:47pm est Mar 26, 2024
@KeijiBranshi
Copy link
Collaborator

Hi @devihall03. Looked into this a little more.

The logs output from your original post shows your client using two separate ports http://127.0.0.1:5501 and http://127.0.0.1:5500:

error: Access to fetch at 'https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/1/model.json?tfjs-format=file' from origin 'http://127.0.0.1:5501' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'http://127.0.0.1:5500' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Kaggle's servers previously just mirrored the requestor's origin in the response headers. I don't understand how, but your tfhub.dev requests might have been sent on one port and handled on another.

I just adjusted the CORS response header to be a * for these tfjs requests. I'm hoping that mitigates this issue, but please post back if you encounter the CORS error again.

@devihall03
Copy link
Author

devihall03 commented Apr 9, 2024

@KeijiBranshi Was working great and it happened again! Just before an important demo!

Screenshot 2024-04-09 at 12 24 49 PM Screenshot 2024-04-09 at 12 31 15 PM Screenshot 2024-04-09 at 12 31 38 PM

Is there anything that can be done to mitigate this???

@devihall03
Copy link
Author

devihall03 commented Apr 9, 2024

http://localhost:4000/ is our local

@KeijiBranshi
Copy link
Collaborator

Hi, we're looking into this issue. Thanks for your patience.

@KeijiBranshi
Copy link
Collaborator

Hi. We rolled out a fix. But please keep up posted if you see this again.

More info here: #908 (comment)

Thanks!

@KeijiBranshi
Copy link
Collaborator

Apologies that this happened before an important demo. For situations like this, I'd highly recommend self-hosting the model on your site. You can download the model directly from Kaggle:

image

Alternatively, you can bundle TF.js models directly into your web apps:

For more support on that, I'd recommend posting in the tensorflow repository since this repo is specifically for the Python tfhub client.

@KeijiBranshi
Copy link
Collaborator

Thanks again for sharing. Since the issue is resolved, I'm going to close these related threads out (#908, #909, #904).

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants