tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.38k stars 1.92k forks source link

401 in "loadModel" when securing directory via .htaccess #476

Closed xam-ps closed 6 years ago

xam-ps commented 6 years ago

TensorFlow.js version

All versions

Browser version

All Browsers

Describe the problem or feature request

When served from a directory which is secured via .htaccess user and password the fetch function in "loadModel" is not working (response from server is 401). I think the function should use the option credentials: 'same-origin'.

tafsiri commented 6 years ago

cc @caisq is there a way to pass credentials (or other options to fetch)?

xam-ps commented 6 years ago

From MDN:

By default, fetch won't send or receive any cookies from the server, resulting in unauthenticated requests if the site relies on maintaining a user session (to send cookies, the credentials init option must be set).`

credentials: The request credentials you want to use for the request: omit, same-origin, or include. To automatically send cookies for the current domain, this option must be provided.

caisq commented 6 years ago

To pass credentials and other parameters for fetch during tf.loadModel calls, you can try the following. await tf.loadModel(tf.io.browserHTTPRequest(url, {credentials: 'same-origin'}));

xam-ps commented 6 years ago

Still getting an 401.

Even gave credentials: 'include' a try, didn't work either.

xam-ps commented 6 years ago

Just tested the solution from @caisq in Firefox, there it is working.

xam-ps commented 6 years ago

Issue was solved in Version 0.12.0