question

NerobovAndrey-7511 avatar image
0 Votes"
NerobovAndrey-7511 asked Jerryzy commented

The remote server returned an error: (429).

Hello! I have 3 services in my company. All services work with one service account and sometime I catch error:
The remote server returned an error: (429). Stack: at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at DD.ProjectApproval.Model.SPListItemExtensions.GetFieldUserValueNew(ListItem item, String fieldName, ClientContext clientContext).
I read microsoft recomendations, but I undurstend about
e.WebRequestExecutor.WebRequest.UserAgent = "NONISV|Contoso|GovernanceCheck/1.0";
GovernanceCheck - Enterprice app name, Do I only have to register new app in Enterprice App or need to configure it else?
Contoso -name of Company, where I can find name in Azure?
1.0 -versions of app, where I can find versions?
And I read about "ExecuteQueryWithIncrementalRetry extension method", Is method better tnan ExecuteQueryRetry in OfficeDevPnP.Core, Version=2.24.1803.0?
Thanks!

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sadomovalex avatar image
1 Vote"
sadomovalex answered sadomovalex commented

it is better to use ExecuteQueryRetry from OfficeDevPnP Core which was designed to avoid throttling issues.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@sadomovalex Thanks! I'm already using ExecuteQueryRetry, but there is 429 error. Do you khnow how use e.WebRequestExecutor.WebRequest.UserAgent? I don't use UserAgent now

0 Votes 0 ·
sadomovalex avatar image sadomovalex NerobovAndrey-7511 ·

ExecuteQueryRetry has parameters retryCount (default value is 10), delay (default value is 500) and user agent:

 public static void ExecuteQueryRetry (this Microsoft.SharePoint.Client.ClientRuntimeContext clientContext, int retryCount = 10, int delay = 500, string userAgent = null);

You may e.g. increase delay from 500 to 1000 (=1 sec) and test how it will work. Also you may pass userAgent directly to this method as last parameter.

0 Votes 0 ·
trevorseward avatar image
0 Votes"
trevorseward answered

You should switch over to use Client ID + Certificate/Secret from username/password. This will be more secure and should also help (but may not eliminate, depending on what you're doing, stamp health, etc.) avoid 429 responses.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jerryzy avatar image
0 Votes"
Jerryzy answered

Hi @NerobovAndrey-7511 ,

Please refer the official document below to use e.WebRequestExecutor.WebRequest.UserAgent for avoid throttling:

78936-snipaste-2021-03-18-10-00-49.png


Avoid getting throttled or blocked in SharePoint Online



Also you can build a extension method ExecuteQueryWithIncrementalRetry also like official document for handling 429 throttling issue.

Thanks
Best Regards


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NerobovAndrey-7511 avatar image
0 Votes"
NerobovAndrey-7511 answered

@Jerryzy-MSFT thanks. but I am already it : using (var ctx = new ClientContext(new Uri(Consts.PortalUrl, UriKind.Absolute)))
{
log.Info(Environment.UserDomainName);
log.Info(Consts.getMailIP);
var creds = new NetworkCredential(Autorization.UserEmail, Autorization.Password);
ctx.Credentials = new SharePointOnlineCredentials(creds.UserName, creds.SecurePassword);
ctx.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.UserAgent = $"NONISV|Digdes|{Consts.AppSettings.Name}/1.0";
};
}
but it don't help me. Probably, is UserAgent wrong? How check it?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jerryzy avatar image
0 Votes"
Jerryzy answered

@NerobovAndrey-7511 ,

I used the UserAgent "NONISV|Contoso|GovernanceCheck/1.0", it's working per the test:

79064-snipaste-2021-03-18-15-38-18.png



But as you have met the 429 error in your environment, you should firstly wait for 429 recovery, then use the UserAgent for avoiding the issue.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NerobovAndrey-7511 avatar image
0 Votes"
NerobovAndrey-7511 answered NerobovAndrey-7511 edited

@Jerryzy-MSFT Where did you get name "GovernanceCheck" and version "1.0" and "Contoso"? Can I use any names?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jerryzy avatar image
0 Votes"
Jerryzy answered

@NerobovAndrey-7511 ,

I'm using the sample in official document, you can use your own value, official document have specified, suggest you check out the official document carefully:

79054-snipaste-2021-03-18-15-57-35.png



And currently, please wait for 429 recovery firstly.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NerobovAndrey-7511 avatar image
0 Votes"
NerobovAndrey-7511 answered

@Jerryzy-MSFT , I saw it, but I don't know Company Name and App name. I have Azure function where I get error 429. Where's the company name and the app name on the screen?79036-image.png



image.png (43.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jerryzy avatar image
0 Votes"
Jerryzy answered Jerryzy edited

@NerobovAndrey-7511 ,

You can use the Tenant name as the comany name and function name as app name.

Besides the UserAgent, it's best to use ExecuteQueryWithIncrementalRetry handle 429 issue as suggested above.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NerobovAndrey-7511 avatar image
0 Votes"
NerobovAndrey-7511 answered

@Jerryzy-MSFT I find tenat names, but which name is more correct? 79038-image.png



image.png (10.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.