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

Always return error "user token expired" when use openAPI platform #12284

Open
sukha-cn opened this issue Jan 8, 2025 · 0 comments
Open

Always return error "user token expired" when use openAPI platform #12284

sukha-cn opened this issue Jan 8, 2025 · 0 comments
Assignees

Comments

@sukha-cn
Copy link

sukha-cn commented Jan 8, 2025

I used the demo code to get access token. When I upload a file, it always return "user token expired" message.

Here is the code:

import hashlib
import random
import time
import requests

def get_nonce():
    pool = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    length = 10
    ret = ""

    while len(ret) < length:
        ret += random.choice(pool)
    return ret


ts = str(int(time.time()))
nonce = get_nonce()
access_key = "***"
secret_key = "***"

concat_string = "uri=/api/v1/openapi/auth&ts=%s&nonce=%s&accessKey=%s&secretKey=%s" % (ts, nonce, access_key, secret_key)
sign = hashlib.sha256(concat_string.encode("utf-8")).hexdigest()

url = "https://platform.openmmlab.com/gw/user-service/api/v1/openapi/auth"
headers = {
    "ts": ts,
    "nonce": nonce,
    "sign": sign,
    "accessKey": access_key
}
ret = requests.post(url, headers=headers)
print(ret.json())

url = "https://platform.openmmlab.com/gw/upload-service/api/v1/uploadFile"

params = {
    "key": "inference",
    "tag": "pose"
}

files = [
    ('file', ('', open('/Users/***/Documents/curry_shot.jpg', 'rb'), 'image/jpeg'))
]

headers = {
    "Authorization": ret.json()['data']['accessToken']
}

response = requests.request("POST", url, params=params, headers=headers, files=files)

print(response.text)

I replace my ak & sk with "***" here for security.

The whole return message is :

{"timestamp":"2025-01-08T02:09:56.576+0000","error":"Internal Server Error","msgCode":"A0202","status":401,"msg":"user token expired"}

I think maybe there is something wrong with the timestamp. But I don't know how to solve the problem.
Please help, thanks.

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

No branches or pull requests

2 participants