Python Forum

Full Version: Convert script from Perl to Python3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! First off I'm not a strong Python developer. I'm a Network Engineer and I use Python to create automation scripts for accessing routers and switches. I've never tried to convert a script of any type. A coworker asked me to help him convert a Perl script to Python. In my research and findings, I'm having some issues trying to find what I need in Python or even making it work.

The Perl script accesses Cisco's Call Manager (phone system) webpage (https, authenication, ignore SSL), it pulls data off the pages, may be more than one with up to 2000 line items on each page. It then parses it (XML) into two columns, userID and extensions, and dumps it into a .CSV file. It then reads that .CSV file, accesses Microsoft Active Directory, looks up the userID and puts the extension of that userID into the persons Active Directory profile under the ipPhone attribute.

The modules the Perl script uses are below vs what I've been trying to use in Python3...

Net::LDAP; = python3-ldap3
LWP::UserAgent; = urllib3
LWP::Protocol::https; = requests
XML::Simple; = lxml

Any help would be appreciated. I'd like to know if I'm using the right equivalents of Python3 and any great examples on how to use these modules.

So far, just even getting Python3 to "get" the URL, pass authentication credentials on the website and to ignore SSL cert has been really hard and frustrating. I'm not getting anywhere with that.

You will need requests, BeautifulSoup ( lxml as a parser or only lxml ), csv module ( it's built-in ). If the webpage is JS generated you will need selenium to handle it. For all of this there is tutorials in this forum ( not sure about lxml alone ): .

Don't know what protocol is using Microsoft Active Directory or how could access it. Can't tell anything about that.

Don't hesitate to ask further if you face some obstacles.
Awesome! Thanks for the help. I will definitely give it a go. Appreciate it.