0

I'm interested to know how I can use provided PAC file to access a website. I'd like to use the data in the file as a proxy input for a get request.

I came across some similar questions, but none of them helped me solve my problem. Anyway, I'll keep them below as a reference:

The minimal example here is:

import requests

pac_url = "https://www.tau.ac.il/remote.pac"
website_url = "https://www.jstor.org/stable/i27924418"
user_name = "user"
password = "pass"

response = requests.get(website_url)
print(response) # <Response [420]>

Obviously, I need to do something in order to make use of the PAC file. So I experiment with a few options:

1 - Define proxy in Windows setting

windows proxy definition

I changed the default proxy setting in Windows to support that PAC and then tried the following code (with request.getproxies() parameter):

import requests
from urllib import request
from requests.auth import HTTPBasicAuth

pac_url = "https://www.tau.ac.il/remote.pac"
website_url = "https://www.jstor.org/stable/i27924418"
user_name = "user"
password = "pass"

response = requests.get(website_url, proxies=request.getproxies(), auth=HTTPBasicAuth(user_name , password))
print(response) # <Response [420]>

2 - Proxy setting in the code

I manually extracted the host name from the pac file and used it:

import requests

pac_url = "https://www.tau.ac.il/remote.pac"
website_url = "https://www.jstor.org/stable/i27924418"
user_name = "user"
password = "pass"

proxies = {
    "http": "http://user:pass@proxy.tau.ac.il:8080/"
}
response = requests.get(website_url, proxies=proxies)
print(response) #<Response [420]>

3 - Using PyPac

I attempted to follow PyPac's installation instructions, but after the next line:

pip install pypac

I received that error

  error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-
tools/

I installed Visual Studio build tools 2019, but it did not resolve the issue. The same message was received again.


So I'm stuck at those three dierctions, wondering what I can do. I would appreciate any assistance.

Yanirmr
  • 749
  • 6
  • 21

0 Answers0