Search code examples
pythonurllib2mechanize

Getting urllib2 Permission denied error while accessing an https webpage?


I made a simple python script to access a webpage and login and retrieve data from it, it worked on my machine using both urllib/urllib2 or mechanize.

So I wanted to use this script in a website so that any user can fill his login credentials on my website and this script will take this data and go fill the other website.

I used OpenShift.com as an online python server and tried my script on it, it worked for all sites that I tried (http/https), but it gave an error with my target website which is:

urllib2.URLError: <urlopen error [Errno 13] Permission denied>

Full error: http://pastebin.com/73vTYEvu

So it's really weird that it worked fine on my machine running ubuntu 15.10 but it's giving this error on the server and only with my target website, and it's a very simple website (link in the script below), I think it's website specific!

I've been searching for this all day long, I tried a lot of way including https specific approaches but still no use.

I don't mind changing the whole method or the server as long as it works :)

My script: (the part that's causing the error)

import urllib2

page = urllib2.urlopen('https://uos.sharjah.ac.ae:9050/prod_enUS/twbkwbis.P_WWWLogin')

print page.read()

Solution

  • Seems like @felipsmartins is right, it's an Openshift specific problem.

    I was able to get my script to work on Heroku easily.