pnp / PnP-Sites-Core

Microsoft 365 Dev PnP Core component (.NET) targeted for increasing developer productivity with CSOM based solutions.
Other
415 stars 642 forks source link

Apply-ProvisioningTemplate -verbose displays (403) Forbidden error messages. #1942

Open pmatthews05 opened 5 years ago

pmatthews05 commented 5 years ago

Category

[x] Bug [ ] Enhancement

Environment

[x] Office 365 / SharePoint Online [ ] SharePoint 2016 [ ] SharePoint 2013

Provisioning a XML template using PNP Powershell. Although the template continues, there is an error stating "System.Net.WebException: The remote server returned an error: (403) Forbidden."

Observed Behavior

Using the latest PNP Powershell Version: 3.2.1810.0 I'm just trying to apply a template to my Team site. It doesn't matter what the template is, or what it is trying to do. This happens if you export a template and then try to import it again.

Steps to reproduce.

Powershell I'm using to create:

Connect-PnPOnline -Url:https://cf.sharepoint.com/sites/pnpdemo -UseWebLogin
Set-PnPTraceLog -On -Level:Debug
Apply-PnPProvisioningTemplate -Path:'./Template.1.xml' -verbose

The process starts off, it trys to connect, and then you get a 403 error, but then it continues.

powershell.exe Information: 0 : 2018-10-12 10:13:30.1885        [OfficeDevPnP.Core]     [0]     [Information]   File Template.1.xml retrieved from folder       0ms
powershell.exe Information: 0 : 2018-10-12 10:13:30.1915        [OfficeDevPnP.Core]     [0]     [Information]   File Template.1.xml retrieved from folder       0ms
powershell.exe Information: 0 : 2018-10-12 10:13:31.1662        [Provisioning]  [15]    [Debug] Code execution scope started    0ms     f7277219-f0f3-44bf-8a1e-c73a9db91e0f
powershell.exe Information: 0 : 2018-10-12 10:13:31.1677        [Provisioning]  [15]    [Information]   ProgressDelegate registered     1ms     f7277219-f0f3-44bf-8a1e-c73a9db91e0f
powershell.exe Information: 0 : 2018-10-12 10:13:31.1683        [Provisioning]  [15]    [Information]   MessagesDelegate registered     3ms     f7277219-f0f3-44bf-8a1e-c73a9db91e0f
powershell.exe Error: 0 : 2018-10-12 10:13:35.7103      [OfficeDevPnP.Core]     [0]     [Error] ExecuteQuery threw following exception: System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.SPWebRequestExecutor.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<GetFormDigestInfoPrivateAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<EnsureFormDigestAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<ExecuteQueryAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__7.MoveNext().  0ms
powershell.exe Error: 0 : 2018-10-12 10:13:35.9572      [OfficeDevPnP.Core]     [0]     [Error] ExecuteQuery threw following exception: System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.SPWebRequestExecutor.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<GetFormDigestInfoPrivateAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<EnsureFormDigestAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<ExecuteQueryAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__7.MoveNext().  0ms
jansenbe commented 5 years ago

Can you repro this when you create a new site collection and then try to apply the template? If so then please share the template used

pmatthews05 commented 5 years ago

Due to company policy, and the size of the template, I have created a brand new template to show this issue.

I have created a new site collection called /sites/otbPnPIssue. I created a couple of site columns, a content type, a list and assigned the content type to the list.

I then got the template by using get-pnpprovisioningtemplate using the latest schema.

I then created a new site collection called /sites/ptbPnPIssue2 (spelling mistake there doh!) Then after this site collection was created, I called apply-pnpprovisioiningtemplate using the .xml from the get-pnprovisioningtemplate.

I have attached the xml, please rename back to pnpissue.xml. pnpissue.xml.txt

As stated previously, the provisioning still happens, but when you have PnpTraceLog set to debug, you get the error message.

jswanborn commented 5 years ago

I am, and have been, experiencing the same issue. The error occurs regardless of PNP Powershell version.

ZHQ1128 commented 5 years ago

@pmatthews05 Have you solved your problem yet? I'm experiencing the same issue as you did, though I'm using pnp in c# but not powershell. If you have solved it, it would be greatly appreciated if you can share your solution.

FilipVG commented 5 years ago

I'm also have the issue. Working with 3.4.1812.2 When it starts with extracting "Page Contents". Underneath the stacktrace: at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.PageExtensions.GetWebPartXml(Web web, Guid webPartId, String serverRelativePageUrl) at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ObjectPageContents.ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.GetRemoteTemplate(Web web, ProvisioningTemplateCreationInformation creationInfo) at SharePointPnP.PowerShell.Commands.Provisioning.Site.GetProvisioningTemplate.ExtractTemplate(XMLPnPSchemaVersion schema, String path, String packageName) at SharePointPnP.PowerShell.Commands.Provisioning.Site.GetProvisioningTemplate.ExecuteCmdlet() at SharePointPnP.PowerShell.Commands.PnPCmdlet.ProcessRecord()

FilipVG commented 5 years ago

Upgraded to latest version. Error still occurs. Name Version


SharePointPnPPowerShell2016 3.5.1901.0 SharePointPnPPowerShellOnline 3.5.1901.0

espiteri commented 5 years ago

I'm also have the issue. Working with 3.4.1812.2 When it starts with extracting "Page Contents". Underneath the stacktrace: at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.PageExtensions.GetWebPartXml(Web web, Guid webPartId, String serverRelativePageUrl) at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ObjectPageContents.ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.GetRemoteTemplate(Web web, ProvisioningTemplateCreationInformation creationInfo) at SharePointPnP.PowerShell.Commands.Provisioning.Site.GetProvisioningTemplate.ExtractTemplate(XMLPnPSchemaVersion schema, String path, String packageName) at SharePointPnP.PowerShell.Commands.Provisioning.Site.GetProvisioningTemplate.ExecuteCmdlet() at SharePointPnP.PowerShell.Commands.PnPCmdlet.ProcessRecord()

We're experiencing the exact same issue and exception. Cmdlet used: Get-PnPProvisioningTemplate

FilipVG commented 5 years ago

Any solution yet? I found out that, when removing all webparts from the homepage, the script ends well. Adding a webpart and than extracting causes an error. But I don't know how to solve it. It is very important that my template has the correct homepage, not an empty one....

FilipVG commented 5 years ago

Eventually, I found the solution. I had the onprem and cloud PNP installed side side. Name Version


SharePointPnPPowerShell2016 3.9.1905.0 SharePointPnPPowerShellOnline 3.9.1905.0

Uninstalling SharePointPnPPowerShell2016 made it work without errors.

sukeshkhare commented 5 years ago

I have only SharePointPnPPowerShellOnline module (no onpremise) but I still get the error when using Apply-PnPProvisioningTemplate

Get-Module sharepoint*

ModuleType Version Name ExportedCommands


Binary 3.8.1904.0 SharePointPnPPowerShellOnline {Add-PnPAlert, Add-PnPApp, Add-PnPClientSidePage, Add-PnPClientSidePageSection...}


powershell.exe Error: 0 : 2019-05-14 12:20:56.5644 [OfficeDevPnP.Core] [0] [Error] ExecuteQuery threw following exception: System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.SPWebRequestExecutor.d0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.db.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.d8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.d4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContextExtensions.d7.MoveNext(). 0ms powershell.exe Error: 0 : 2019-05-14 12:20:56.9299 [OfficeDevPnP.Core] [0] [Error] ExecuteQuery threw following exception: System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.SPWebRequestExecutor.d0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.d__b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


I have below as well Set-PnpTraceLog -Level Debug -On

Regards, Sukesh