I've been trying to read a file that is under a URI following the file://
protocol since is in a shared folder, not in local like this post, the open
function does not work.
The file is reachable with my user locally by using the following code.
uri = "//128.0.0.1/hello_world.txt"
with open(uri, 'r') as f:
contents = f.read()
print(contents)
I want to automate that and I've created a Distributed user that can access the shared folder over a Proxy. I don't think the open
method can be executed by another user like the problem targeted here neither can add a Proxy in their Configuration.
I've tried other libraries but I couldn't find any that can handle the file://
protocol. For example, for requests library:
import requests
uri = "//128.0.0.1/hello_world.txt"
PATH = f"http:{uri}"
proxies = {"http": f'http://{proxy_user}:{proxy_password}@proxy.com:1234',
"https": f'https://{proxy_user}:{proxy_password}@proxy.com:1234'
}
x = requests.get(PATH, proxies=proxies)
print(x.status_code)
Or this one using urllib
:
from urllib import request
uri = "//128.0.0.1/hello_world.txt"
PATH = f"file:{uri}"
proxies = {"http": f'http://{proxy_user}:{proxy_password}@proxy.com:1234',
"https": f'https://{proxy_user}:{proxy_password}@proxy.com:1234'
}
opener = request.FancyURLopener(proxies)
with opener.open(PATH) as f:
print(f.read().decode('utf-8'))
I have tried samba
as well in order to read from there.
Did anyone find a library that can handle file://
protocol properly?
Thank you in advance.