Problem uploading excel file to SharePoint with LDAP - python

I am trying to upload an Excel file to SharePoint, using the code I found here, but so far, I cannot manage to make it work with my LDAP account. Getting this error:
raise ShareplumRequestError("Shareplum HTTP Post Failed", err)
shareplum.errors.ShareplumRequestError: Shareplum HTTP Post Failed :
HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url:
/extSTS.srf (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at
0x000001B24A126B08>: Failed to establish a new connection: [WinError 10061] No connection could
be made because the target machine actively refused it'))
with this code:
from shareplum import Office365
from shareplum import Site
from shareplum.site import Version
def main():
sp = r"//foo.sharepoint.com/sites/foobarwiki/Shared Documents/SourceExcelFile.xlsx"
cp = r"C:\Users\Git\SourceExcelFile.xlsx"
authcookie = Office365('https://foo.sharepoint.com', username='un', password='pwd').GetCookies()
site = Site(r'https://foo.sharepoint.com/sites/foobarwiki/', version=Version.v365, authcookie=authcookie);
folder = site.Folder('Shared Documents/foobarbar/')
with open(cp, mode='rb') as file:
fileContent = file.read()
folder.upload_file(fileContent, "myfile.txt")
print("Done!")
if __name__ == "__main__":
main()
As this can be considered an xy question, in the meantime, I tried simply using shutil.copy(cp, sp) and .copy2, as it should be ok and I am quite ok to access the SharePoint with other ways, but still no success there as I guess shutil does not like SharePoint a lot.
Any ideas?

Related

Requests - Python - Failed to establish a new connection: [Errno 111] Connection refused

I have a server running in Ubuntu OS, and I am using Python for getting to learn.
I started an app which I installed, When I opened the app in browser the page is not secure, like this -
I am getting some data from this page using python -
from urllib3.exceptions import InsecureRequestWarning
import requests
requests.urllib3.disable_warnings(category=InsecureRequestWarning)
req = requests.get(url='https://127.0.0.1:7001', verify=False)
This shows an error -
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='127.0.0.1', port=7001): Max retries exceeded with url: / (Caused by
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fc2ae5f94f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
When I print the variable req to check the status, but python shows the variable is not defined
How to solve this, thanks
HTTPSConnectionPool(host='127.0.0.1', port=443)
443 is the default port for HTTPS.
You're probably (we can't see how you've defined url, but that's my best guess) trying https://127.0.0.1/..., not https://127.0.0.1:7001/... – fix that in your code.

New Connection Error when trying to use requests.get at python 3.7

well i've been trying to download a File directly from a URL, the thing is, when I do it at home it works perfectly fine, but when I try to run it at my company's server it doesn't work.
My code is:
import requests
url = "https://servicos.ibama.gov.br/ctf/publico/areasembargadas/downloadListaAreasEmbargadas.php"
response = requests.get(url, verify=False)
url = open("teste.zip", "w")
url.write(response.content)
url.close()
and the error message that i get is:
HTTPSConnectionPool(host='servicos.ibama.gov.br', port=443): Max retries exceeded with url: /ctf/publico/areasembargadas/downloadListaAreasEmbargadas.php (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001F2F792C0F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
I konw that we use proxy here, i've been looking for solutions for this problem and I could see that this is relevant, but I couldn't find something to do with this information

How could I deploy a tabpy code when I already have an API endpoint running using django in an virtual environment?

I am trying to create an api endpoint using django in python and restrserve in R and deploying the below code in tabpy to connect with tableau and I am facing with this error.Could someone recommend on any solution.
Error message:
ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=9004): Max
retries exceeded with url: /endpoints (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000016136C007C8>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it'))
Code:
import tabpy_client
import requests
client = tabpy_client.Client('http://127.0.0.1:9004')
def external_services_say_hello(message, service):
if service == 'PYTHON':
r = requests.post('http://127.0.0.1:8000/', data ={'message': message})
elif service == 'R':
r = requests.post('http://localhost:8080/hello', data = {'message': message,})
serviceResult = r.json()
return serviceResult['result']
client.deploy('external_services_say_hello', external_services_say_hello, 'Make Python or R say Hello or anything you want.', override = True)
print('*** Model deployed successfully ***')
Thanks in advance!

Python Requests Deployment

In on of my Django view´s I am making a request to another webserver via requests, this code works perfect when I run the code with the development server. It looks like that:
import requests
r = requests.post('http://www.example.org')
return r.text
But when I Deploy this an apaches www-data user is running it it throws this error:
ConnectionError
HTTPConnectionPool(host='www.example.com', port=80): Max retries exceeded
with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection
object at 0x7f23e917ba58>:Failed to establish a new connection:[Errno -2]
Name or Service not known'))
But I can run the code as root user from a seperate script on the Deployment server without a problem this is why i think it is a permission problem. But i have no Idea how to solve this.
Thanks in advance!

Download .gz file using requests in Python Error

I would be very grateful if anyone could help me with this issue I am having.
I’m trying to use the request lib to download a .gz file from the internet. I have successfully used the lib before to get xml data that is parsed to the browser, but the .gz version is not working.
Once the URL_To_Gzip link is clicked in my browser, the .gz file automatically starts to download the file. --> so the url is ok, but just points directly to the file.
I’m trying to code this in python 2.7 so I can then process the file and data it contains, but I get an error message that I am struggling to resolve.
Error Message:
HTTPSConnectionPool(host=HOST_URL_TO_GZip, port=443): Max retries exceeded with url: URL_TO_GZip.gz (Caused by : [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)
import requests
data = requests.get(url_to_gzip,proxies = {"http":proxy_url}) # Does not work data = #Does not work
data = requests.get(url_to_gzip,proxies = {"http":proxy_url}, stream = True) # Does not work
The information on Errno 10060 suggests the error is related to my proxy, as a connection can not be established. --> But I have successfully used these to get the xml data in a similar version.
Thanks,
Ravi
EDIT
The URL_TO_GZip.gz file is via a https:// whereas the xml file that works ok is via a http:// which I think is the cause of my problem and why it works for one file but not another.
For anyone else that comes across this issue, I needed to add a auth = (username, password) keyword to access the HTTPS site auth keyword.

Categories

Resources