Forum Settings
Forums

MySQL Error when using the API to update my list

New
Apr 20, 2016 1:07 PM
#1
Offline
Jan 2015
11
I'm writing a program to choose a show from my PTW list at random, then update it in my list.

The program chooses an anime fine, but when updating, I get this message after sending the HTTP post request:

"There was a MySQL error, the staff have been notified and are looking in to it. Updated"

But I can update shows using the MAL website, so it's not a problem on the server side itself, I suppose. The code I'm using is here:

try
	{
		string url = "http://myanimelist.net/api/animelist/update/" + id + ".xml";
		HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
		request.Method = "POST";	//the type of request
		request.Credentials = new NetworkCredential(un, pw);	//authentication details
		request.ContentType = "text/xml; encoding='utf-8'";

		string xmlDoc = "<?xml version="1.0" encoding="UTF-8"?>n" +
					"<entry>n" +
					"\t<episode></episode>n" +
					"\t<status>1</status>n" +
					"\t<score></score>n" +
					"\t<storage_type></storage_type>n" +
					"\t<storage_value></storage_value>n" +
					"\t<times_rewatched></times_rewatched>n" +
					"\t<rewatch_value></rewatch_value>n" +
	               			"\t<date_start></date_start>n" +
					"\t<date_finish></date_finish>n" +
					"\t<priority></priority>n" +
					"\t<enable_discussion></enable_discussion>n" +
					"\t<enable_rewatching></enable_rewatching>n" +
					"\t<comments></comments>n" +
					"\t<fansub_group></fansub_group>n" +
					"\t<tags></tags>n" +
		        		"</entry>";
			byte[] docBytes;
			docBytes = System.Text.Encoding.ASCII.GetBytes(xmlDoc);	//need to encode the data properly
			request.ContentLength = docBytes.Length;

			Stream requestStream = request.GetRequestStream();
			requestStream.Write(docBytes, 0, docBytes.Length);
			requestStream.Close();

			HttpWebResponse response = request.GetResponse() as HttpWebResponse;

			if (response.StatusCode == HttpStatusCode.OK)
			{
				Stream responseStream = response.GetResponseStream();
				string responseStr = new StreamReader(responseStream).ReadToEnd();
				Console.WriteLine(responseStr);
			}
		}

		catch (Exception e)
		{
			Console.WriteLine(e.Message);
		}


No exceptions occur, and the HTTP status code is "OK". So I am really puzzled.
cow_coApr 20, 2016 1:29 PM
Apr 21, 2016 2:11 AM
#2

Offline
Oct 2009
7667
Try replacing
xmlDoc = "<?xml

with
xmlDoc = "data=<?xml

Also, I am not sure you need those \n and \t, or maybe you do... You also don't need to paste every single possible value, you may skip the ones you don't update
Apr 21, 2016 10:24 AM
#3
Offline
Jan 2015
11
OK, I'll try that! And it's good that I don't need to paste every value. That simplifies things a lot. I'll get back to you once I've tested it!
Apr 21, 2016 11:28 AM
#4
Offline
Jan 2015
11
Aight, so that didn't quite work, but it put me on course for the correct answer:

private static void UpdateList(int id, string un, SecureString pw)
		{
			try
			{
				WebClient client = new WebClient();
				string url = "http://myanimelist.net/api/animelist/update/" + id + ".xml";
				client.BaseAddress = url;
				client.Credentials = new NetworkCredential(un, pw);	//authentication details
				client.Encoding = System.Text.Encoding.UTF8;
				
				string xmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
								"<entry>\n" +
								"\t<status>1</status>\n" +
								"</entry>";

				client.QueryString = new System.Collections.Specialized.NameValueCollection();
				client.QueryString.Add("data", xmlDoc);
				Console.Write(client.UploadValues(url, client.QueryString));
			}

			catch (Exception e)
			{
				Console.WriteLine(e.Message);
			}
		}

More topics from this board

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

vasipi4946 - 6 hours ago

2 by deg »»
27 minutes ago

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

Kineta - Sep 21, 2015

3372 by GARFIELDD666 »»
5 hours ago

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

DariTheWeeb - Feb 19

49 by DeadPiles »»
9 hours ago

» 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