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

expired token #46

Closed
alexislg2 opened this issue Feb 8, 2017 · 8 comments
Closed

expired token #46

alexislg2 opened this issue Feb 8, 2017 · 8 comments

Comments

@alexislg2
Copy link

Hey.
For few days now I receive this errors:
code: 401, reason: Unauthorized, response:{u'status': {u'code': 11001, u'description': u'Invalid authentication token', u'details': u'expired token'}}

I think the reason is because my token is expired. Indeed I save the clarifaiApp and modelvariables because it takes too long to initialize (at least 5 seconds).

Is there any workaround to avoid initializing the token for every photo I want to process?

@robertwenquan
Copy link
Contributor

Hi @alexislg2

Definitely it's not taking a new token every time you process a photo. I am suspecting you are instantializing the client every time you process a photo?

Could you paste me your code snippet how you use our api?

Thanks,
Robert

@alexislg2
Copy link
Author

Here is my code:

# This is called only when program starts
from clarifai.rest import ClarifaiApp
clarifaiApp = ClarifaiApp(app_id="CLARIFAI_APP_ID", app_secret="CLARIFAI_KEY")
clarifai_model_sfw = clarifaiApp.models.get("nsfw-v1.0")

def checkSFW(url):
    # This is called only when we process a picture
    try:
        concept = clarifai_model_sfw.predict_by_url(url)["outputs"][0]["data"]["concepts"][0]
        score = concept["value"]
        sfw_rate = score if concept["name"] == "sfw" else 1-score
        if (sfw_rate > 0.15):
            return True
        return False
    except:
        return True

@alexislg2
Copy link
Author

@robertwenquan is my code OK?
With this code I receive "Expired token" errors after ~24h.

Did clarifai changed anything in their API? I did not get these errors one month ago

@robertwenquan
Copy link
Contributor

@alexislg2 token is expected to expire. That's for the consideration of security in case the token is compromised. However, it's automatically managed by the client so you don't have to worry about it. The code looks fine to me. Ohh, maybe it's the warning issue introduced in the recent version? It's just a warning and your code should run fine. Because the token is refreshed automatically. Did you see your code actually failed or did you just see this error ?

@alexislg2
Copy link
Author

No it raises an exception :

concept = clarifai_model_sfw.predict_by_url(url)["outputs"][0]["data"]["concepts"][0]
---------------------------------------------------------------------------
ApiError                                  Traceback (most recent call last)
<ipython-input-26-600ba944b001> in <module>()
----> 1 concept = clarifai_model_sfw.predict_by_url(url)["outputs"][0]["data"]["concepts"][0]

[...]/site-packages/clarifai/rest/client.pyc in predict_by_url(self, url)
   1578 
   1579     image = Image(url=url)
-> 1580     res = self.predict([image])
   1581     return res
   1582 

[...]/site-packages/clarifai/rest/client.pyc in predict(self, inputs)
   1635     '''
   1636 
-> 1637     res = self.api.predict_model(self.model_id, inputs, self.model_version)
   1638     return res
   1639 

[...]/site-packages/clarifai/rest/client.pyc in predict_model(self, model_id, objs, version_id)
   2463 
   2464     data = {"inputs": [obj.dict() for obj in objs]}
-> 2465     res = self.post(resource, data)
   2466     return res.json()
   2467 

[...]/site-packages/clarifai/rest/client.pyc in post(self, resource, params, version)
   1938   def post(self, resource, params=None, version="v2"):
   1939     ''' Authorized post to Clarifai's API. '''
-> 1940     return self._requester(resource, params, 'POST', version)
   1941 
   1942   def post_form(self, resource, params=None, version="v2"):

[...]/site-packages/clarifai/rest/client.pyc in _requester(self, resource, params, method, version, files)
   1929       attempts -= 1
   1930     if res.status_code != 200:
-> 1931       raise ApiError(resource, params, method, res)
   1932     return res
   1933 

ApiError: POST models/e9576d86d2004ed1a38ba0cf39ecb4b1/versions/a6b3a307361c4a00a465e962f721fc58/outputs FAILED. code: 401, reason: Unauthorized, response:{u'status': {u'code': 11001, u'description': u'Invalid authentication token', u'details': u'expired token'}}

@robertwenquan
Copy link
Contributor

robertwenquan commented Feb 15, 2017 via email

@alexislg2
Copy link
Author

@robertwenquan Any news on this?

could this be the same reason why your website demo is not working? https://clarifai.com/demo

@robertwenquan
Copy link
Contributor

@alexislg2 this bug has been fixed in v2.0.20
please take your time to upgrade the client.

The demo outage is not relevant to this issue. It's because of an overuse of our demo that exhaused our api quota.

I am closing this issue as this is fixed. Thanks again for reporting it

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

No branches or pull requests

2 participants