Receiving an invalid token (403-Forbidden) error from POST when using Python d2lValence library....

Options
Joe.Price4842
Joe.Price4842 Posts: 2 🌱
edited November 2022 in Development

Receiving an invalid token (403-Forbidden) error from POST when using Python d2lValence library. Exact call is successful (200-OK) when using .NET d2Valence library.
 

Hello - I have been using the D2LValence .NET extension for quite some time to automate the downloading and processing of BDS reports. We have need of the Advanced Data Sets so I am developing a similar script in Python for this purpose. In the script, I can make GET calls successfully but the first POST call I make returns a 403-Forbidden error with an invalid token message.

 

I am using the same app and user credentials and decorating the URL using the create_authenticated_url method as I use for the successful GET calls. I thought that maybe my user context didn't have appropriate permissions for the POST call so I tested the same call in .NET. It works successfully using .NET. I'm attaching screenshots of the code and the raw request and response data intercepted via BurpSuite. There are no obvious differences between the two calls.

 

I can use .NET to finish this project but I was hoping to use Python going forward. Please let me know if you can help. Thank you!

 

Pythonpython_codeUsing the create_authenticated_url method and requests.post in Python

 

.NETnet_codeUsing the ValenceAuthenticator.Authenticate method and RestSharp.RestRequest in .NET.

 

Python Request\Response (RAW)

python_request 

.NET Request\Response (RAW)

dotnet_requestThanks for any help you can offer. Hopefully it's something easy that I'm overlooking.

 

@Paul Paton​ 

@Matias Marabotto​ 

Tagged:

Answers

  • Gauthaman.Ravindran8571
    edited November 2022
    Options

    Hello, Joseph:

     

    I believe that with the create_authenticated_url , you'll need to specify the HTTP verb:

     

    url = app_context_2.create_authenticated_url('/d2l/api/lp' + cfg_lp + '/dataExport/create', 'POST')

     

    If you look at your .NET example, you'll see that you specified "Method.POST" when creating the request.

     

    Hopefully this will help.

     

     

  • Joe.Price4842
    Joe.Price4842 Posts: 2 🌱
    edited November 2022
    Options

    AWESOME! Thank you so much @Gauthaman Ravindran​ !! That did it!!