Authentication error with MetaMask using Python and Django

Hi !
I’m using Authentication API with MetaMask using Python and Django on my project (https://docs.moralis.io/authentication-api/evm/how-to-sign-in-with-metamask-python-django).
I have an issue connecting with a Ledger wallet, the status code of the request in verify_message() is 400 instead of 201.
It works fine with standard MetaMask wallet (hotwallet).
Any idea how to solve that ?

For information:
def verify_message(request):
data = json.loads(request.body)
REQUEST_URL = ‘https://authapi.moralis.io/challenge/verify/evm
x = requests.post(
REQUEST_URL,
json=data,
headers={‘X-API-KEY’: API_KEY})
if x.status_code == 201:
# user can authenticate
eth_address=json.loads(x.text).get(‘address’)
eth_address = eth_address.lower()
try:
user = User.objects.get(username=eth_address)
except User.DoesNotExist:
user = User(username=eth_address)
user.is_staff = False
user.is_superuser = False
user.save()
if user is not None:
if user.is_active:
login(request, user)
request.session[‘auth_info’] = data
request.session[‘verified_data’] = json.loads(x.text)
return JsonResponse({‘user’: user.username})
else:
return JsonResponse({‘error’: ‘account disabled’})
else:
return JsonResponse(json.loads(x.text))

Hi @th3x4v

Since the same code is working with metamask wallet, the issue is not from the code.

Can you try comparing the signature message that you see in metamask and in your ledger? If they look different then it is possible that the ledger is making some modifications to the message.

You can check the length of the returned signature. It can also be because it usually takes more time to sign a message with ledger and you have to increase the timeout value for auth api

Yes !
Thank you.

no i have server error(500) i have to deal with :wink: