I am currently trying to understand Paypal APIs by writing a flask app which consumes various APIs. What i have bugun with is interacting with Permission services for classic APIs. I have a sandbox account which provides me with the necessities to make my requests. In one of my view functions i have succefully accessed the request permission page and received a the paypal's redirect to the callback Url i provided in my request. This is my code(note that i am still 'young' in python so suggestions for improvement are welcomed)
@account.route('/grant_auth')
def get_request_token():
    """handle the proccess of getting the request token"""
    if request.method == 'GET':
    url = "https://svcs.sandbox.paypal.com/Permissions/RequestPermissions"
    headers = {
        'X-PAYPAL-SECURITY-USERID': '**********',
        'X-PAYPAL-SECURITY-PASSWORD': '*********',
        'X-PAYPAL-SECURITY-SIGNATURE': '************',
        'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON',
        'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON',
        'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T'
    }
    payload = {
        'scope': 'ACCOUNT_BALANCE',
        'callback': 'http://127.0.0.1:5000/access_token',
        'request_Envelop': {
            'errorLanguage': 'en_US'
        }
    }
    res_details = requests.post(
        url, data=json.dumps(payload), headers=headers)
    res_json_format = res_details.json()
    if str(res_json_format['responseEnvelope']['ack']) == 'Failure':
        return render_template('account.html', response='something went wrong with the application')
    if str(res_json_format['responseEnvelope']['ack']) == 'Success':
        token = res_json_format['token']
        pal_permission_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token={}'.format(token)
        return redirect(pal_permission_url)
    else: 
        return render_template('account.html', response='something went wrong with the application')
Thats what i have done:
When i run that code and i visit /grant_auth
I am redirected to the paypal page where i can grant the permission when i grant i am redirected  to http://127.0.0.1:5000/access_token?request_token=somevalue&verification_code=somevalue with an additonal parameters appended to it as such.
- Please help me how i can obtain the verifiaction_code and request_token from the url(or even better what is the best direction to go from here) since i need the two values to make another request to the GetAccesToken API so that i can make requests on behalf of users who have granted the permission.
Retrieving parameters from a URL seems to slightly address my problem but not fully because the url being parsed there is already existing unlike my case where the url changes. Thanks in Advance
