Forum Settings
Forums
New
Sep 3, 2017 9:44 AM
#1
Offline
Apr 2014
23
Hi,

I'm trying to use MyAnimeList API, it's working the firsts time but after some tries I get a 403 error :/

Here's my code:
foreach (string t in allTags)
{
    try
    {
        using (WebClient wc = new WebClient())
        {
            wc.Credentials = new NetworkCredential("username", "password");
            string result = wc.DownloadString("https://myanimelist.net/api/anime/search.xml?q=plastic+memories");
            Console.WriteLine(result);
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}


Does someone please know why ?

Thanks in advance
Oct 29, 2017 9:18 AM
#2

Offline
Sep 2012
3601
Can you try to define "wc.Credentials" out of loop? A guess but that can cause a 403 error. Also what that loop does? I mean what is "allTags"?
Dec 13, 2017 3:59 PM
#3
Offline
Apr 2014
23
Hi, I'm sorry for not responding for so long :/
I changed my code and it's now looking like that:
[Command("MyAnimeList")]
public async Task mal(string animeName)
{
    p.doAction(Context.User, Context.Guild.Id, Program.Module.MyAnimeList);
    using (WebClient wc = new WebClient())
    {
        wc.Credentials = new NetworkCredential("username", "password");
    }
	// Some other stuff
}

So I no longer have a loop, and the creditentials are right (because it's working like 4 times then it's not working anymore, I also login on the website just before writing it to be sure).
Mar 21, 2018 2:19 AM
#4

Offline
Aug 2012
4162
Discord.NET?

It doesn't work after x tries because that's a security feature afaik. You log in after every invoke of the command. Repeatedly logging in would trigger something in most cases :>

Try using the credentials during init and see how that goes. But you've probably moved on and used a different service if you still haven't solved it at this point xD
Mar 21, 2018 5:44 AM
#5
Offline
Apr 2014
23
Hi,

Thanks for your reply, I tried to set the credentials at the beginning of the program but it still not working (I get a 403 error after a few tried) :/
Oct 13, 2022 12:54 AM
#6
Offline
Oct 2022
4
If the 403 error was reported from other resources, there might be another cause for the error. For example:

If the error was reported in a web browser, then that error might be caused by an incorrect proxy setting. The proxy server returns a 403 error if HTTP access isn't allowed.
If there's another AWS service in front of the API, then that service can reject the request with a 403 error in the response.

Hope You Find This Useful,
Peter

More topics from this board

» I can't use forums using Windows High Contrast anymore

vasipi4946 - Yesterday

3 by traed »»
13 minutes ago

Sticky: » Inactive Username Request Thread ( 1 2 3 4 5 ... Last Page )

Kineta - Sep 21, 2015

3372 by GARFIELDD666 »»
Yesterday, 10:02 PM

» [Reported] Username being auto-pasted into search bar

DariTheWeeb - Feb 19

49 by DeadPiles »»
Yesterday, 6:03 PM

» IP ban glitch?

AverageRiceFan - Apr 21

2 by hich4n_ »»
Yesterday, 12:15 PM

» ishinashi has 300 alt accounts and counting ( 1 2 3 )

deg - Jun 16, 2023

127 by Spunkert »»
Yesterday, 6:05 AM
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login