Error Code 429 when attempting to download page's HTML - c#

I'm not really a developer and only just coded during university and for fun. I'm currently working on a small project involved in web scraping with c# and I can't seem to download the HTML code from the website I want, see code below.
private asynch void GetHTML1()
{
//Crownbet
string crownbet_url = "https://crownbet.com.au/sports-betting/australian-rules/afl/afl-matches/";
HttpClient crownbet_httpClient = new HttpClient();
var crownbet_html = await crownbet_httpClient.GetStringAsync(crownbet_url).Result;
HtmlAgilityPack.HtmlDocument crownbet_htmlDocument = new HtmlAgilityPack.HtmlDocument();
crownbet_htmlDocument.LoadHtml(crownbet_html);
}
When I run this code I get the following error.
Exception thrown:
'System.Net.WebException' in System.dll An unhandled exception of type
'System.Net.WebException' occurred in System.dll The remote server
returned an error: (429) Calm down.
I'm not too sure what's wrong here because I've used this method to grab HTML code from other websites and it seems to work fine. Status 429 is usually given when you send too many requests to a website right?

Related

What causes "WinHttpException: The server returned an invalid or unrecognized response" in HttpClient?

PROBLEM:
I am trying to access data from a remote Bugzilla server using Bugzilla's REST API. Whenever I await a response from HttpClient.GetAsync, this exception is thrown.
WHAT I'VE TRIED:
In an effort to understand the exception, I've investigated the following SO questions and GitHub issues:
Meaning of “The server returned an invalid or unrecognized response” in HttpClient
The server returned an invalid or unrecognized response" error when ...
HttpClient fails with "The server returned an invalid or unrecognized ...
CORE CODE:
The purpose of the code below is to get the Bugzilla version of the server at _url_version. For example, if I set _url_version = "https://bugzilla.mozilla.org/rest/version", I get a valid response.
// Get version, dummy test to ensure REST API is working via http requests
public async Task<string> GetVersion()
{
using (var client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(_url_version);
string json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<Rootobject>(json).version;
}
}
QUESTION:
What is the meaning of this exception? What could be causing the communication break between my application and the remote Bugzilla server?
After doing some digging, I was able to resolve this issue by updating Bugzilla to 5.0.4.
ROOT CAUSE:
By using Curl, I was able to manually examine the headers from the Http response (here). The exception was being caused by noise in the response:
Bugzilla.pm:sysread() is deprecated on :utf8 handles. This will be a fatal error in Perl 5.30 at C:/...
For some reason, this issue with a perl module was being echoed on the server side.
SOLUTION:
According the Bugzilla 5.0.4 release notes, the issue was resolved. I updated my Bugzilla installation and the REST API worked as intended.
Hopefully this is helpful to someone out there!

How to Remove 'System.Net.WebException' occurred in System.dll where server returned an error code of (500)

I am using webclient to upload my files to server via Rest Service. I am checking my code by debugging it on a local host what I found is my server is successfully receiving all these files but at client end where I have a code for sending file I am getting this exception.
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (500) Internal Server Error."
The code I am using is below:
var Filereqparam = new System.Collections.Specialized.NameValueCollection();
using (var lWebClient = new WebClient()) {
foreach (var file in data.file) {
Filereqparam.Add("FileName", file.FileName);
Filereqparam.Add("FileExtension", file.FileExtension);
Filereqparam.Add("FileData", file.FileData);
System.Diagnostics.Debug.WriteLine( Filereqparam);
var recvFiledata = lWebClient.UploadValues("http://localhost:56156/api/userfiles/getfiles", Filereqparam);
var respFileBody = Encoding.UTF8.GetString(recvFiledata);
}
}
I have set the time limit for client to unlimited, but still I am unable to resolve this issue. My question is why I am receiving this exception if my files are successfully sent to server?
Note: If anyone know a better way to upload the large files to server via rest service then please share your technique.

System.net.webexception in system.dll

I have followed this tutorial to update a powerbi dashboard here.
I have copied all the code from Microsoft's website. Of course I have supplied my own clientId.
The console application successfully creates a dataset, but does not add rows to the table.
It fails here:
var response = (HttpWebResponse)request.GetResponse();
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (404) Not Found.
The URL you are querying is wrong or no longer exists. Check the documentation for the APIs you are querying to make sure you are properly constructing the URL.
Start here for PowerBI APIs: https://msdn.microsoft.com/library/dn877544.aspx

c# console app error (The process was terminated due to an unhandled exception)

I want to hit a url every 5 mins. I built a c# console app called myconsoleapp.exe and scheduled this in the windows task scheduler:
c#
static void Main(string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.mypage.aspx");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
however I am getting this error? :
Error:
Application: myconsoleapp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Net.WebException Stack: at System.Net.HttpWebRequest.GetResponse() at myconsoleapp.Program.Main(System.String[])
You might get this error for various reasons such as:
- Timeout on web server side
- Name not resolving to an IP address
- Lack of connectivity to the Internet
- Invalid URL
- Other network or web site related problems
My advices:
- Get more info by looking at the error message in the exception
- Handle the exception so as to retry upon failure before giving up
- Investigate any connectivity, DNS resolution or any other network related problem

webclient bugging out or what?

hi
I ran my project yesterday just fine, but today when I ran the same code it hangs on WebClient.DownloadFile() and eventually times out with this error message:
"An unhandled exception of type 'System.Net.WebException' occurred in System.dll"
So I tried running only the webclient in a new project, downloading from a hardcoded url that I know is up like this.
static void Main(string[] args)
{
WebClient client = new WebClient();
client.DownloadFile("http://www.ashersarlin.com/cartoons/officerap2.gif", "pic.gif");
}
Same thing happens. It creates an empty file "pic.gif" but times out eventually.
I could use some pointers. I'm new to .NET and have no idea how to troubleshoot this.
Your exact code works for me...
Perhaps your default proxy is messed up?
Suggestions:
Print out the detail of the WebException - it may give more hints
Use Wireshark to see what's going on at the network level. That should show you if it's trying to connect, what it's getting back etc.

Categories

Resources