Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No XML document #149

Open
chrisandthetopher opened this issue Dec 18, 2018 · 17 comments
Open

No XML document #149

chrisandthetopher opened this issue Dec 18, 2018 · 17 comments

Comments

@chrisandthetopher
Copy link

I have had this script running for months, but this morning I am getting the following error:

[18-Dec-2018 12:02:50 Australia/Melbourne] PHP Fatal error: Uncaught Exception: Error (Client) looks like we got no XML document,more= in /home/jppporta/public_html/advocate/email-unsub/Thybag/SharePointAPI.php:1016
Stack trace:
#0 /home/jppporta/public_html/advocate/email-unsub/Thybag/SharePointAPI.php(446): Thybag\SharePointAPI->onError(Object(SoapFault))
#1 /home/jppporta/public_html/advocate/email-unsub/Thybag/Service/QueryObjectService.php(210): Thybag\SharePointAPI->read('JPP Contact Lis...', 1, Object(Thybag\Service\QueryObjectService), NULL, NULL, NULL)
#2 /home/jppporta/public_html/advocate/email-unsub/sharepoint_unsub.php(26): Thybag\Service\QueryObjectService->get()
#3 {main}
thrown in /home/jppporta/public_html/advocate/email-unsub/Thybag/SharePointAPI.php on line 1016

Any ideas?

@djansen1987
Copy link

HI found a solution to the issue? Got similar error:

Fatal error: Uncaught Exception: Error (Client) looks like we got no XML document,more= in /home/xxxxxxxx/public_html/xxxxxxxx/sharepoint/src/Thybag/SharePointAPI.php:1016 Stack trace: #0 /home/xxxxxxxx/public_html/xxxxxxxx/sharepoint/src/Thybag/SharePointAPI.php(446): Thybag\SharePointAPI->onError(Object(SoapFault)) #1 /home/xxxxxxxx/public_html/xxxxxxxx/sharepoint/index.php(22): Thybag\SharePointAPI->read('Change Manageme...') #2 {main} thrown in /home/xxxxxxxx/public_html/xxxxxxxx/sharepoint/src/Thybag/SharePointAPI.php on line 1016

@chrisandthetopher
Copy link
Author

No solution yet.

@djansen1987
Copy link

Hi Chris,

Thanks for you response, hope the creators of thybag know how to fix it.

@thybag
Copy link
Owner

thybag commented Jan 19, 2019

Hi both,

Do you have any example code that can replicate the bug at all? (Also be good to know what SP version your running against / what auth method your using).

The Error (Client) looks like we got no XML document message is coming direct from the SP API, so am guessing its not like something that being posted at it. It may be an API change in a newer version (I don't have access to a SP instance to test with these days, so unsure if they have introduced any breaking changes)

May also be worth checking its nothing to do with trailing white space / the BOM in the php file itself ( https://stackoverflow.com/questions/4313952/soap-looks-like-we-got-no-xml-document )

@chrisandthetopher
Copy link
Author

chrisandthetopher commented Jan 20, 2019

Hi,

Mine is just a form that accepts an email address and edits a field in Sharepoint online...this is the relevant part of the page:

if(!empty($_POST['usremail'])) {
$sp =  new Thybag\SharePointAPI('username', 'password', 'https://BUSINESSNAME.sharepoint.com/_vti_bin/Lists.asmx?WSDL', 'SPONLINE'); 
$data = $sp->query('Contact List')->where('Email','=',$usremail)->limit(1)->sort('Title','FirstName','Email','DESC')->get();` 
foreach($data as $key => $value)        
{        
if(!empty($value['id'])){
$spid = $value['id'];
}
if(!empty($value['no_x0020_newsletter'])){
$spnl = $value['no_x0020_newsletter'];
}
}
if(isset($spid)) {
$sp2 =  new Thybag\SharePointAPI('username', 'password', 'https://BUSINESSNAME.sharepoint.com/_vti_bin/Lists.asmx?wsdl', 'SPONLINE'); 
$data2 = $sp2->updateMultiple('Contact List', array(
array('ID'=>$spid,'No_x0020_Newsletter'=>$true)
));
echo 'Thanks, You have been unsubscribed.';
} else {
echo 'Email address not found.';
}
} else {
echo 'Must enter a value!';
}

This was working for months, then one day just stopped...I use a similar piece of code in another part of the site and this has also stopped working without any changes on my end, so they may have changed the API

@djansen1987
Copy link

djansen1987 commented Jan 21, 2019

basis of the script

require_once('SharePointAPI.php');

use Thybag\SharePointAPI;
$sp = new SharePointAPI('username', 'password', 'https://BUSINESSNAME.sharepoint.com/sites/SITENAME/_vti_bin/Lists.asmx?WSDL', 'SPONLINE');

$data = $sp->read('Change Management');

as the code does not display well i added in a notepad:

sharepoint draft.txt

@thybag
Copy link
Owner

thybag commented Feb 7, 2019

Ah, i think that may well be a headers sent to early issue. (basically any whitespace or content before the php)

Basically having any code before the <?php (like the css), will cause the server to start sending data to the client, meaning its no longer able to update the headers (sent before this data) which will break things like SOAP potentially.

Would suggest moving the SharePoint api php right to the top of the file and having all other markup after its done requesting whatever data you need.

@djansen1987
Copy link

Hi Thybag,

Thanks for your response. Striped down the script to only have below. But got the same error (with debug on):

`<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

require_once('SharePointAPI.php');

use Thybag\SharePointAPI;
$sp = new SharePointAPI('[email protected]', 'SecurePassword', 'https://company.sharepoint.com/sites/teamsite/_vti_bin/Lists.asmx?WSDL', 'SPONLINE');

$data = $sp->read('List Name');
?>`

@chrisandthetopher
Copy link
Author

Hi,

I also tried with no luck...I stripped everything except the sharepoint code out, but got the same error:

<?php include "Thybag/SharePointAPI.php"; include "Thybag/Auth/SharePointOnlineAuth.php"; include "Thybag/Auth/SoapClientAuth.php"; include "Thybag/Auth/StreamWrapperHttpAuth.php"; include "Thybag/Service/ListService.php"; include "Thybag/Service/QueryObjectService.php"; $sp = new Thybag\SharePointAPI('USERNAME', 'PASSWORD', 'https://businessname.sharepoint.com/_vti_bin/Lists.asmx?wsdl', 'SPONLINE'); $data = $sp->read('Contact List', 10); ?>

@djansen1987
Copy link

Today it started working again suddenly without changing anything to the code.
Any clue how this is possible ?

@chrisandthetopher
Copy link
Author

Weird...mine is still not working

@djansen1987
Copy link

mine stopped working an hour later.

@CakeBit
Copy link

CakeBit commented Mar 16, 2019

Quick fix. Try replacing

if($loop[0] == 'Set-Cookie') {

with

if(strtolower($loop[0]) == 'set-cookie') {

on line 136 in SharePointOnlineAuth.php.

Sharepoint Online (Office365) is no longer returning Set-Cookie capitalized in the response headers. This causes extractAuthCookies in SharePointOnlineAuth.php to return no cookies as it looks for an exact string match of 'Set-Cookie'. This then prevents future requests from Authenticating (I was seeing 403 FORBIDDEN returned, which the XML parser was complaining about). The fix is not requiring the case to be an exact match when searching for cookies in the header string.

If someone wants to make a pull request or include a cookie parser, feel free to improve on this.

thybag added a commit that referenced this issue Mar 16, 2019
@thybag
Copy link
Owner

thybag commented Mar 16, 2019

Hi @CakeBit - have applied your fix directly to develop 👍

(I no longer have access to any SharePoint instances to test stuff myself, so am generally avoiding making many changes. That said, your fix sounded sensible & entirely safe. Cheers for the suggestion.)

36d4436

@CakeBit
Copy link

CakeBit commented Mar 16, 2019

@thybag Thanks so much!

In your commit Set-Cookie should also be lowercased ('set-cookie') so that PHP can match against it. As it stands currently it will not find any cookies because it's searching a header converted to lowercase against a string with capitalization. 👀

Maybe in the future a Cookie Parser could be implemented (here's one such example on StackOverflow).

@thybag
Copy link
Owner

thybag commented Mar 16, 2019

🤦‍♂️ Fixed.

@chrisandthetopher
Copy link
Author

That seems to have fixed my issue...thank you very much.

renahorton218 added a commit to renahorton218/Lists-API-build-SharePoint that referenced this issue Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants