web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / While using Run Python...
Power Automate
Answered

While using Run Python Script Action i am facing the issue

(0) ShareShare
ReportReport
Posted on by 31

Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named requests

Using the Run Python Script action to upload a file attachment, but facing the above error 
can someone help me on the issue

I have the same question (0)
  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @Vamsi_Envoy 

     

    Could you show the python code 

     

    Also do you have the python2 installed in your system?

  • Vamsi_Envoy Profile Picture
    31 on at

    @Nived_Nambiar 
    Yes i have installed the Python2 in my machine.
    My Code:
    -----------------------------------
    import requests
    url = "RequestUrl"
    payload={'baseDocumentId': 'f8152e6c',
    'documentTypeId': '1449',
    'isReferenceDocument': 'true',
    'baseProfileIds': '4feff1756478',
    'sendNotifications': 'false',
    'legalMatterId': '586207365964'}
    files=[
    ('file',('Capture.PNG',open('C:\\Users\\Downloads\\Capture.png','rb'),'application/octet-stream'))
    ]
    headers = {
    'Authorization': 'Bearer Token'
    }
    response =requests.request("POST", url, headers=headers, data=payload, files=files)
    print(response)
    But this is the same code working fine in Run DOS Command Action but the thing is my bot was unable to find uploading is successfull or not if it not success my bot needs to retry the same process.

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @Vamsi_Envoy 

     

    Use this modified code 🙂

     

    import sys
    sys.path.append(r"c:\Python27\Lib")
    import requests
    url = "RequestUrl"
    payload={'baseDocumentId': 'f8152e6c',
    'documentTypeId': '1449',
    'isReferenceDocument': 'true',
    'baseProfileIds': '4feff1756478',
    'sendNotifications': 'false',
    'legalMatterId': '586207365964'}
    files=[
    ('file',('Capture.PNG',open('C:\\Users\\Downloads\\Capture.png','rb'),'application/octet-stream'))
    ]
    headers = {
    'Authorization': 'Bearer Token'
    }
    response =requests.request("POST", url, headers=headers, data=payload, files=files)
    print(response)

    PAD need to identify where the request module is, so I have added 2 lines of codes at starting. Hope it helps 🙂

     

    Mark it as solution if it resolves your query

  • Vamsi_Envoy Profile Picture
    31 on at

    @Nived_Nambiar 
    Facing the same issue again with the below
    Traceback (most recent call last):
    File "<string>", line 3, in <module>
    ImportError: No module named requests

  • Verified answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @Vamsi_Envoy 

     

    Not sure why it is not working, i was reffering one post where using this same technique it worked there.

     

    But you have told me that it using Run DOS command it is working, But you are not getting output, have you check the variable which stores output of that command in run dos action ?

     

  • Vamsi_Envoy Profile Picture
    31 on at

    HI @Nived_Nambiar 
    I tried with Open CMD,Write to CMD Session,Read CMD Sesssion and Close the CMD actions it's working fine with same Python Script code i am  able to uplaod file attachments, thanks for your resposne

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 246 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 176

#3
Haque Profile Picture

Haque 157

Last 30 days Overall leaderboard