B4J Question Need translation from python to b4j

Siam

Active Member
Licensed User
Longtime User
Hello,

can someone help me to import this python script to B4J each try i have done ends in an internal server error or i don't get the token. and i have to say that i'm not a python programmer.

Python:
#!/usr/bin/env python3
import sys
import requests
import json
rBody = {'userName': 'guest@qubic.li', 'password': 'guest13@Qubic.li', 'twoFactorCode': ''}
rHeaders = {'Accept': 'application/json', 'Content-Type': 'application/json-patch+json'}
r = requests.post('https://api.qubic.li/Auth/Login', data=json.dumps(rBody), headers=rHeaders)
token = r.json()['token']
print(token)

thanks for your advice

Andy
 
Last edited:
Solution
B4X:
Sub GetToken
    ' Code_jOkHttpUtils2_Post_Json
    Dim job As HttpJob
    job.Initialize("", Me)
    Dim payload As Map = CreateMap("userName": "guest@qubic.li", "password": "guest13@Qubic.li", "twoFactorCode": "")
    Dim json As String = payload.As(JSON).ToString
    job.PostString("https://api.qubic.li/Auth/Login", json)
    job.GetRequest.SetContentType("application/json-patch+json")
    Wait For (job) JobDone (job As HttpJob)
    If job.Success Then
        Dim response As Map = job.GetString.As(JSON).ToMap
        Log(response.Get("token"))
    End If
    job.Release
End Sub

aeric

Expert
Licensed User
Longtime User
B4X:
Sub GetToken
    ' Code_jOkHttpUtils2_Post_Json
    Dim job As HttpJob
    job.Initialize("", Me)
    Dim payload As Map = CreateMap("userName": "guest@qubic.li", "password": "guest13@Qubic.li", "twoFactorCode": "")
    Dim json As String = payload.As(JSON).ToString
    job.PostString("https://api.qubic.li/Auth/Login", json)
    job.GetRequest.SetContentType("application/json-patch+json")
    Wait For (job) JobDone (job As HttpJob)
    If job.Success Then
        Dim response As Map = job.GetString.As(JSON).ToMap
        Log(response.Get("token"))
    End If
    job.Release
End Sub
 

Attachments

  • httpjob.zip
    1,018 bytes · Views: 127
Upvote 0
Solution
Top