0

When I run this script at home, I get the results I need, but when I run it on corporate networks it does not work I get WinError 10060, I tried different proxy and everythign but couldnt get it to run and I need to have it running on the corporate network beacause that is where the voice techs are going to be running the script.

I'd be greatful if anybody can point me in the right direction.

import sys, http.client  

showlines = 50
npa = []

try:
    servername = sys.argv[1]

except:
    servername = 'localcallingguide.com'
server = http.client.HTTPConnection(servername)

for i in range(1000):
    if i < 10:
        npa.append('00' + str(i))
    elif i >= 10 and i < 100:
        npa.append('0' + str(i))
    else:
        npa.append(str(i))

for i in range(len(npa)):
    filename = '/lca_rcdist.php?npa1=503&nxx1=745&npa2=503&nxx2=' + npa[i]
    server.putrequest('GET', filename)
    server.putheader('Accept', 'text/html')
    server.endheaders()
    reply = server.getresponse()

    if reply.status != 200:
         print('Error sending request', reply.status, reply.reason)
    else:
        data = reply.readlines()
        reply.close()
        for line in data[:showlines]:
            cLine = line.decode('utf-8')
            if '"ofrom">N<' in cLine:
                 print('NXX ,' + npa[i])
pzhrk
  • 21
  • 4
  • Ask your IT how web browsers work on your corporate network, then do the same thing for your software. "I tried different proxy and everythign" doesn't help unless you're trying the proxy they've set up (assuming it's even a proxy that's the issue). If IT refuse to help, there are ways you could figure it out yourself—but then they'll probably just shut you down anyway once they realize you've made an end-run around their policy. – abarnert Sep 13 '13 at 20:53
  • I know how they work, everything is filtered by a corporate proxy, but we have a proxy setup just for our department that lets up bypass the corporate one for testing purposes. I couldn't get it to run through that proxy either. – pzhrk Sep 13 '13 at 21:13
  • Someone would need a lot more information than you've given to help you debug this. Can you reach the same URL that script is using from your browser? What about from a command-line tool like `curl` or `wget`? What code did you use to go through the proxy? – abarnert Sep 14 '13 at 01:20
  • Meanwhile, why are you using `http.client` instead of something higher-level, like `urllib.request` (or, outside the stdlib, `requests`)? It's very easy to screw up your proxy code with `http.client`, but it's trivial with `urllib` (especially if it can auto-detect your proxy from the environment variables). – abarnert Sep 14 '13 at 01:22
  • I tried urllib too without any luck. I'm pretty new to python, maybe I wasn't adding urllib in the right place, can you show me what exactly I would need to replace with urllib in the script above? – pzhrk Sep 19 '13 at 14:57
  • And yes I can get to the site using my browser – pzhrk Sep 19 '13 at 14:58
  • I used examples from http://stackoverflow.com/questions/5620263/using-an-http-proxy-python to set proxy but had no luck. – pzhrk Sep 19 '13 at 15:06
  • I don't see anything in your code that sets a `ProxyHandler`. What did you try? – abarnert Sep 19 '13 at 18:45
  • Also, even if you're properly using `HTTP_PROXY` to configure a `ProxyHandler`, that will only work if the browser happens to be using `HTTP_PROXY` to get its proxy settings. That's only one of many ways that browsers can do it—they could have been manually configured by IT, they could use either Microsoft-style or Netscape-style proxy autodetect, etc. You have to know which mechanism your browser is using and do the same thing, not just pick one at random. – abarnert Sep 19 '13 at 18:48
  • @ pzhrk : Can you please take a look in my problem? [link](http://stackoverflow.com/questions/23825642/python-get-html-from-url?noredirect=1#comment36658851_23825642) – Trenera May 23 '14 at 11:05

0 Answers0