0

I am trying to get a list of items from Sharepoint using Shareplum, but it seems to be giving me an error just by accessing the site:

from shareplum import Site, Office365
from shareplum.site import Version

main_link = 'https://xxxxxxx.sharepoint.com'
whole_link = 'https://xxxxxxxxx.sharepoint.com/sites/TheSiteNeededToRun'

###LINE GIVING THE ERROR###    
cookie = Office365(main_link, username=usr, password=pwd).GetCookies()
###LINE GIVING THE ERROR###

site = Site(whole_link, version=Version.v365, authcookie=cookie)

mnps_list = site.List(mnps_list_name)
data = mnps_list.GetListItems('All Items')

This is the complete error (at the end, it says something about "Shareplum HTTP Post Failed," thus the title):

C:\Users\victoraz\Documents\auto-mnp>python access-sp.py
Traceback (most recent call last):
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 156, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:        

Traceback (most recent call last):
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 300, in connect
    conn = self._new_conn()
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 168, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x000001C909FA5580>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:        

Traceback (most recent call last):
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /extSTS.srf (Caused 
by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001C909FA5580>: Failed to establish a new connection: [Errno 11001] 
getaddrinfo failed'))

During handling of the above exception, another exception occurred:        

Traceback (most recent call last):
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\shareplum\request_helper.py", line 16, in post
    response = session.post(url, **kwargs)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /extSTS.srf (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001C909FA5580>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:        

Traceback (most recent call last):
  File "C:\Users\victoraz\Documents\auto-mnp\access-sp.py", line 11, in <module>
    cookie = Office365(main_link, username=usr, password=pwd).GetCookies() 
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\shareplum\office365.py", line 88, in get_cookies
    sectoken = self.get_security_token(self.username, self.password)       
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\shareplum\office365.py", line 66, in get_security_token
    response = post(requests, url, data=body)
  File "C:\Users\victoraz\AppData\Local\Programs\Python\Python39\lib\site-packages\shareplum\request_helper.py", line 20, in post
    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.VerifiedHTTPSConnection object at 0x000001C909FA5580>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

I suspect of the function .GetCookies(), since I commented almost everything from .GetCookies() to the last line, and ran the module without exceptions (albeit, without the program doing anything, either).

vzazu
  • 1
  • 1
  • The error says `socket.gaierror: [Errno 11001] getaddrinfo failed`. This means the DNS host name is wrong. Most likely, the `xxxxxxx ` part is wrong. Can you open that URL in the browser at all? – Panagiotis Kanavos Mar 30 '21 at 06:35
  • Does this answer your question? ["getaddrinfo failed", what does that mean?](https://stackoverflow.com/questions/7334199/getaddrinfo-failed-what-does-that-mean) – Panagiotis Kanavos Mar 30 '21 at 06:44
  • Hello, yes I can access the link, though I have been doing some testing in Postman and I arrived to the same conclusion as you, there is something weird with the DNS. Albeit, I cannot figure out what exactly. – vzazu Mar 30 '21 at 17:38

1 Answers1

-1

My test code:

from shareplum import Site
from shareplum import Office365
from shareplum.site import Version

authcookie = Office365('https://contoso.sharepoint.com/', username='amos@contoso.onmicrosoft.com', password='password').GetCookies()
site = Site('https://contoso.sharepoint.com/sites/dev/', version=Version.v2016, authcookie=authcookie)

list=site.List("test3");
data=list.GetListItems("All Items");
print(data)

Test result: enter image description here Check if you have enabled Multi-Factor Authentication.

Amos
  • 1,762
  • 1
  • 3
  • 7
  • How does this *answer* the question? Especially when `getaddrinfo failed` means there's a DNS issue? SO isn't a discussion forum like Technet Forums, it's a Q&A site. The Answers have to be actual Answers – Panagiotis Kanavos Mar 30 '21 at 06:34
  • Besides, what you posted doesn't work. `contoso.sharepoint.com` is a fictitious DNS name used in tutorials. Your own screenshot shows you used a *different site* – Panagiotis Kanavos Mar 30 '21 at 06:39
  • I just don’t want to show the tenant name I used for testing in the code. – Amos Mar 30 '21 at 06:42
  • Will your test code directly use someone else's tenant? – Amos Mar 30 '21 at 06:43
  • You did expose the name. It's in the screenshot. Again, SO isn't Technet Forums. Answers should actually answer the question. The question's error complains about a bad DNS name, not authentication – Panagiotis Kanavos Mar 30 '21 at 06:43
  • Do you think his tenant name will be "xxxxxxx"? – Amos Mar 30 '21 at 06:47
  • I just give the results of my testing his code, and speculate on the possible reasons for the code error. – Amos Mar 30 '21 at 06:49
  • I think you should delete this question because the original image is still in the edit history. And read [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). I've already flagged the question. – Panagiotis Kanavos Mar 30 '21 at 06:50