jasonrollins / shareplum

Pythonic SharePoint
MIT License
179 stars 96 forks source link

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: _api/lists/getbytitle('2G')/RenderListDataAsStream shareplum.errors.ShareplumRequestError: Shareplum HTTP Post Failed : 400 Client Error: Bad Request for url: getbytitle('2G')/RenderListDataAsStream #148

Closed dhouhadaoud closed 3 years ago

dhouhadaoud commented 3 years ago

I always get this error I'm having issue with shareplum when I call site.List('2G'), anyone can help me? Thanks

ERROR raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:_api/lists/getbytitle('2G')/RenderListDataAsStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "get_info_spt.py", line 24, in main() File "get_info_spt.py", line 15, in main sp_list = site.List('2G') File "/.env2/lib/python3.7/site-packages/shareplum/site.py", line 501, in list site_url=self.site_url, File ".env2/lib/python3.7/site-packages/shareplum/list.py", line 520, in init self.schema = self._get_schema() File ".env2/lib/python3.7/site-packages/shareplum/list.py", line 532, in _get_schema response = post(self._session, url=url, headers=headers, data=body, timeout=self.timeout) File ".env2/lib/python3.7/site-packages/shareplum/request_helper.py", line 20, in post raise ShareplumRequestError("Shareplum HTTP Post Failed", err) shareplum.errors.ShareplumRequestError: Shareplum HTTP Post Failed : 400 Client Error: Bad Request for url: _api/lists/getbytitle('2G')/RenderListDataAsStream

Jay-Kopf commented 3 years ago

I've got same Issue.

I'm using SharePoint Server 2016 on premise.

url = "https://****/sites/test"
cred = HttpNtlmAuth("***\\****", "****")
site = Site(url, Version.v2016, auth=cred)
list = site.List("TestDocs")

Getting the site is no problem and in site.lists I can see the List:

{
 'AllowAnonymousAccess': 'false', 
 'AnonymousViewListItems': 'false', 
 'BaseTemplate': 'DocumentLibrary', 
 'BaseType': 'DocumentLibrary', 
 'DefaultViewUrl': '/sites/test/TestDocs/Forms/AllItems.aspx', 
 'Description': None, 
 'InheritedSecurity': 'true', 
 'InternalName': '{F77F244B-334B-4994-9239-55657A12D66D}', 
 'LastModified': '2021-02-19 11:10:08Z', 
 'ReadSecurity': '1', 
 'Title': 'TestDocs'
}

But when I call site.List("TestDocs") I get the same exception:

ShareplumRequestError("Shareplum HTTP Post Failed : 400 Client Error: Bad Request for url: https://***/sites/test/_api/lists/getbytitle('TestDocs')/RenderListDataAsStream")

Jay-Kopf commented 3 years ago

Actual workaround for this: site = Site(url, Version.v2010, auth=cred)

I have to create the site with v2016 to upload files in a folder and to change ItemProperties of this file I need to create the site with v2010 to get the List.

jasonrollins commented 3 years ago

So this is failing with the _get_schema() function that is utilized if you choose a newer version of SharePoint. I've tested this with the online version of Office365, maybe it doesn't work with SharePoint 2016 on prem? Can you open a web browser and try using that url to see if it's just a bad url? I can go back to using SOAP instead of the JSON API if 2016 on prem doesn't support this method.

Jay-Kopf commented 3 years ago

Browser isn't working:

The HTTP method 'GET' cannot be used to access the resource 'RenderListDataAsStream'. The operation type of the resource is specified as 'Default'. Please use correct HTTP method to invoke the resource.

I tried a POST Request in Postman with NTLM Authorization and X-RequestDigest and an Empty Body:

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <m:code>-2147467261, System.ArgumentNullException</m:code>
    <m:message xml:lang="en-US">No value was specified for the {0} parameter.&#xD;
Parameter name: parameters.ViewXml</m:message>
</m:error>

Did you use a ViewXml in the Body?

dhouhadaoud commented 3 years ago

@jasonrollins Thanks for your help , it works with the version 2010