sdrose65 / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

The remote server returned an error: (400) Bad Request. When uploading Video to youtube from Youtube API. #527

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
when trying to upload a video to youtube via the api i am getting a error as 
"The remote server returned an error:(400) Bad Request". 

I'm using the Youtube API and can successfully upload locally but not on 
production server. The following is the error message i receive:

The remote server returned an error: (400) Bad Request.

This is the code I am using:

Video v = new Video();
v.Title = row["title"] .ToString();
v.Description = row["description"].ToString();
v.Keywords = row["keywords"].ToString();
v.Private = false;
v.MediaSource = new MediaFileSource(strPath, contentType);
AtomLink link = new 
AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + 
this.youtubeAccount + "/uploads");
link.Rel = ResumableUploader.CreateMediaRelation;
v.YouTubeEntry.Links.Add(link);

 private void OnProgress(object sender, AsyncOperationProgressEventArgs e)
        {
            try
            {
                UserState u = e.UserState as UserState;

                if (u != null && u.Row != null)
                {
                    string status = "";
                    if (u.RetryCounter > 1)
                    {
                        status = "Retrying (" + (u.RetryCounter - 1).ToString() + "), uploading: " + e.ProgressPercentage + "% done";
                    }
                    else
                    {
                        status = "Uploading: " + e.ProgressPercentage + "% done";
                    }

                    Trace.TraceInformation("OnProgress: " + status);
                    Trace.Indent();
                    Trace.TraceInformation("Verb: " + e.HttpVerb);
                    Trace.TraceInformation("Uri: " + e.Uri);
                    Trace.TraceInformation("Current position: " + e.Position);
                   // lblMessage.Text += "Current position: " + e.Position + "\r\n";
                    Trace.Unindent();

                    u.CurrentPosition = e.Position;
                    u.ResumeUri = e.Uri;
                    u.HttpVerb = e.HttpVerb;
                    // u.Row.Cells[COLUMNINDEX_STATUS].Value = status;
                    lblProgress.Text = status;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                lblMessage.Text += ex.Message.ToString() + "\r\n";
            }
        }

 private void OnDone(object sender, AsyncOperationCompletedEventArgs e)
        {
            try
            {
                if (e != null)
                {
                    UserState u = e.UserState as UserState;

                    Trace.TraceInformation("OnDone - Upload finished for :" + u.ResumeUri);
                    Trace.Indent();
                    if (u != null && u.Row != null)
                    {
                        if (e.Cancelled == true)
                        {
                            Trace.TraceInformation("Cancelled. Current Pos = " + u.CurrentPosition);
                            MessageBox.Show("Cancelled. Current Pos = " + u.CurrentPosition);
                            lblMessage.Text += "Cancelled. Current Pos = " + u.CurrentPosition + "\r\n";
                            u.RetryCounter = 0;
                            AddToRetryQueue(u);
                        }
                        else if (e.Error != null)
                        {
                            try
                            {
                                Trace.TraceInformation("Error. Current Pos = " + u.CurrentPosition);
                                Trace.TraceInformation("Error was: " + e.Error.ToString() + " - " + e.Error.Message);
                                MessageBox.Show("Error. Current Pos = " + u.CurrentPosition);
                                MessageBox.Show("Error was: " + e.Error.ToString() + " - " + e.Error.Message);
                                lblMessage.Text += "Cancelled. Current Pos = " + u.CurrentPosition + "\r\n";
                                lblMessage.Text += "Error was: " + e.Error.ToString() + " - " + e.Error.Message + "\r\n";
                                u.Error = e.Error.Message;
                                //TryARetry(u);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString() + e.Error.Message);
                                lblMessage.Text += ex.Message.ToString() + "\r\n" + e.Error.Message + "\r\n";
                            }

                        }
                        else
                        {
                            ParseAndFinish(u, e.ResponseStream);
                        }
                    }

                    Trace.Unindent();
                }

                if (Finished() == true)
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + e.Error.Message);
                lblMessage.Text += ex.Message.ToString() + "\r\n";
            }
        }
Kindly please suggest me, where I am wrong.......

Original issue reported on code.google.com by tswapn...@gmail.com on 20 Jul 2011 at 2:38

GoogleCodeExporter commented 9 years ago
when trying to upload a video to youtube via the api i am getting a error as 
"The remote server returned an error:(400) Bad Request". 

I'm using the Youtube API and can successfully upload locally but not on 
production server. The following is the error message i receive:

System.Net.WebException: The remote server returned an error: (400) Bad Request.

   at System.Net.HttpWebRequest.GetResponse()

   at Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, AbstractEntry entry)

   at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, AbstractEntry payload, AsyncData data)

   at Google.GData.Client.ResumableUpload.ResumableUploader.AsyncInsertWorker(AsyncResumableUploadData data, AsyncOperation asyncOp, SendOrPostCallback completionMethodDelegate) - The remote server returned an error: (400) Bad Request.

This is the code I am using:

Video v = new Video();
v.Title = row["title"] .ToString();
v.Description = row["description"].ToString();
v.Keywords = row["keywords"].ToString();
v.Private = false;
v.MediaSource = new MediaFileSource(strPath, contentType);
AtomLink link = new 
AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + 
this.youtubeAccount + "/uploads");
link.Rel = ResumableUploader.CreateMediaRelation;
v.YouTubeEntry.Links.Add(link);

 private void OnProgress(object sender, AsyncOperationProgressEventArgs e)
        {
            try
            {
                UserState u = e.UserState as UserState;

                if (u != null && u.Row != null)
                {
                    string status = "";
                    if (u.RetryCounter > 1)
                    {
                        status = "Retrying (" + (u.RetryCounter - 1).ToString() + "), uploading: " + e.ProgressPercentage + "% done";
                    }
                    else
                    {
                        status = "Uploading: " + e.ProgressPercentage + "% done";
                    }

                    Trace.TraceInformation("OnProgress: " + status);
                    Trace.Indent();
                    Trace.TraceInformation("Verb: " + e.HttpVerb);
                    Trace.TraceInformation("Uri: " + e.Uri);
                    Trace.TraceInformation("Current position: " + e.Position);
                   // lblMessage.Text += "Current position: " + e.Position + "\r\n";
                    Trace.Unindent();

                    u.CurrentPosition = e.Position;
                    u.ResumeUri = e.Uri;
                    u.HttpVerb = e.HttpVerb;
                    // u.Row.Cells[COLUMNINDEX_STATUS].Value = status;
                    lblProgress.Text = status;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                lblMessage.Text += ex.Message.ToString() + "\r\n";
            }
        }

 private void OnDone(object sender, AsyncOperationCompletedEventArgs e)
        {
            try
            {
                if (e != null)
                {
                    UserState u = e.UserState as UserState;

                    Trace.TraceInformation("OnDone - Upload finished for :" + u.ResumeUri);
                    Trace.Indent();
                    if (u != null && u.Row != null)
                    {
                        if (e.Cancelled == true)
                        {
                            Trace.TraceInformation("Cancelled. Current Pos = " + u.CurrentPosition);
                            MessageBox.Show("Cancelled. Current Pos = " + u.CurrentPosition);
                            lblMessage.Text += "Cancelled. Current Pos = " + u.CurrentPosition + "\r\n";
                            u.RetryCounter = 0;
                            AddToRetryQueue(u);
                        }
                        else if (e.Error != null)
                        {
                            try
                            {
                                Trace.TraceInformation("Error. Current Pos = " + u.CurrentPosition);
                                Trace.TraceInformation("Error was: " + e.Error.ToString() + " - " + e.Error.Message);
                                MessageBox.Show("Error. Current Pos = " + u.CurrentPosition);
                                MessageBox.Show("Error was: " + e.Error.ToString() + " - " + e.Error.Message);
                                lblMessage.Text += "Cancelled. Current Pos = " + u.CurrentPosition + "\r\n";
                                lblMessage.Text += "Error was: " + e.Error.ToString() + " - " + e.Error.Message + "\r\n";
                                u.Error = e.Error.Message;
                                //TryARetry(u);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString() + e.Error.Message);
                                lblMessage.Text += ex.Message.ToString() + "\r\n" + e.Error.Message + "\r\n";
                            }

                        }
                        else
                        {
                            ParseAndFinish(u, e.ResponseStream);
                        }
                    }

                    Trace.Unindent();
                }

                if (Finished() == true)
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + e.Error.Message);
                lblMessage.Text += ex.Message.ToString() + "\r\n";
            }
        }
Kindly please suggest me, where I am wrong.......

Original comment by swapna...@gmail.com on 20 Jul 2011 at 6:37

GoogleCodeExporter commented 9 years ago
Hi,

As you told, I fallow up here for this issue.

Kindly suggest me where am I going wrong.

Thanks.....

Original comment by tswapn...@gmail.com on 20 Jul 2011 at 8:58

GoogleCodeExporter commented 9 years ago
Can you capture the HTTP traffic using a tool like Fiddler and paste the 
capture here?

Original comment by ccherub...@google.com on 20 Jul 2011 at 11:04

GoogleCodeExporter commented 9 years ago
Hi,

Thanks for your response.

I am attaching the captured HTTP traffics (.saz) file,and png file(I have taken 
a screen shot of it) which I have taken it from my server.

Kind Regards.

Original comment by tswapn...@gmail.com on 21 Jul 2011 at 2:54

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

can anyone please update me on this issue.
I am not able to move forward........
when I am tried for the first time on Server it worked fine......but later on 
it keeps on giving me this error:

Error was: System.Net.WebException: The remote server returned an error: (400) 
Bad Request.

   at System.Net.HttpWebRequest.GetResponse()

   at Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, AbstractEntry entry)

   at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, AbstractEntry payload, AsyncData data)

   at Google.GData.Client.ResumableUpload.ResumableUploader.AsyncInsertWorker(AsyncResumableUploadData data, AsyncOperation asyncOp, SendOrPostCallback completionMethodDelegate) - The remote server returned an error: (400) Bad Request.

need help on this........

Original comment by tswapn...@gmail.com on 21 Jul 2011 at 11:43

GoogleCodeExporter commented 9 years ago
Every time the server returns a 400 error, it also add an error message 
describing why your request is invalid.
If you check the response message in your capture, it reads:

<?xml version='1.0' 
encoding='UTF-8'?><errors><error><domain>yt:validation</domain><code>too_long</c
ode><location 
type='xpath'>media:group/media:keywords/text()</location></error></errors>

Basically, your keywords field is too long.
For all YouTube API requirements, please check the YouTube API documentation.

Original comment by ccherub...@google.com on 22 Jul 2011 at 12:30

GoogleCodeExporter commented 9 years ago
Thanks for your Help.

It solved my problem.

Original comment by tswapn...@gmail.com on 25 Jul 2011 at 2:27

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,

Sometimes when I tried to upload 27MB file I am getting  
"System.Net.WebException: The operation has timed out" error.

I have tried to set time out period:

  YouTubeService service = new YouTubeService(YouTubeUploader.ApplicationName, Helper.strYTUN, Helper.strDKey);
                ((GDataRequestFactory)service.RequestFactory).KeepAlive = false;
                ((GDataRequestFactory)service.RequestFactory).Timeout = 9999999;

                if (this.credentials != null)
                {
                    try
                    {
                        this.youTubeAuthenticator = new ClientLoginAuthenticator(YouTubeUploader.ApplicationName,ServiceNames.YouTube, this.credentials);
                        this.youTubeAuthenticator.DeveloperKey = this.developerKey;
                    }
                    catch
                    {
                        this.youTubeAuthenticator = null;
                    }
                }

                if (this.youTubeAuthenticator == null)
                {
                    this.credentials = new GDataCredentials(UploadToYouTube.Helper.strYTUN, UploadToYouTube.Helper.strYTPWD);
                    // this.credentials = new GDataCredentials("tswapnars@yahoo.co.in", "swapna12");
                    if (this.credentials != null)
                    {
                        this.youTubeAuthenticator = new ClientLoginAuthenticator(YouTubeUploader.ApplicationName,ServiceNames.YouTube, this.credentials);
                        this.youTubeAuthenticator.DeveloperKey = UploadToYouTube.Helper.strDKey;
                        this.youtubeAccount = UploadToYouTube.Helper.strYTUN;
                    }
                    else
                    {
                        this.Close();
                    }
                }

but after about 5 mins I am getting error message saying Time Out period.....

Cancelled. Current Pos = 25690111

Error was: System.Net.WebException: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse()
   at Google.GData.Client.ResumableUpload.ResumableUploader.UploadStreamPart(Int32 partIndex, String httpMethod, Uri sessionUri, Authenticator authentication, Stream payload, String mediaType, AsyncData data)
   at Google.GData.Client.ResumableUpload.ResumableUploader.UploadStream(String httpMethod, Uri sessionUri, Authenticator authentication, Stream payload, String mediaType, AsyncData data)
   at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, AbstractEntry payload, AsyncData data)
   at Google.GData.Client.ResumableUpload.ResumableUploader.AsyncInsertWorker(AsyncResumableUploadData data, AsyncOperation asyncOp, SendOrPostCallback completionMethodDelegate) - The operation has timed out

I am using C# windows appln.....

Can you please tell me where am I setting time period wrong.
How can I set timeout period.

Thanks.

Original comment by tswapn...@gmail.com on 25 Jul 2011 at 7:17

GoogleCodeExporter commented 9 years ago
Please use the discussion group 
(https://groups.google.com/forum/#!forum/gdata-dotnet-client-library) for usage 
questions and this issue tracker only to report issues in the library.
Thanks

Claudio

Original comment by ccherub...@google.com on 25 Jul 2011 at 5:11

GoogleCodeExporter commented 9 years ago
Thanks for your response.

I fallow up there.

Original comment by tswapn...@gmail.com on 25 Jul 2011 at 11:45

GoogleCodeExporter commented 9 years ago
http://www.google.com/ig/calculator?hl=en&q=0GBP%3D%3FGBP

The remote server returned an error: (400) Bad Request.

code is

            try{
            WebClient web = new WebClient();

           // string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);

            Uri uri =new Uri(string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount));

        string  url = uri.AbsoluteUri + uri.Fragment;

            string response = web.DownloadString(url);

            Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
            Match match = regex.Match(response);

                string Strrate = match.Groups[1].Value;

                string[] strratearray = Strrate.Split('.');

                string digitrate = strratearray[0].ToString();
                string decimalrate="0";
                if(strratearray.Length==2)
                     decimalrate = strratearray[1].ToString();

Original comment by surinder...@gmail.com on 31 May 2012 at 1:28

GoogleCodeExporter commented 9 years ago
http://www.google.com/ig/calculator?hl=en&q=0GBP%3D%3FGBP

The remote server returned an error: (400) Bad Request.

please solve it

send me solution below emai id
ssingh2@myzealit.com

Original comment by surinder...@gmail.com on 31 May 2012 at 1:29

GoogleCodeExporter commented 9 years ago
Hi Surinder,

When I click the link it gives me..."{lhs: "0 British pounds",rhs: "0 British 
pounds",error: "0",icc: true}"

Can you please explain me, what you suppose to do?
The above 'The remote server returned an error: (400) Bad Request' which i got 
was, when I try to upload videos to youtube via Google API.

Is that what are you looking for?

Regards,
Swapna.

Original comment by tswapn...@gmail.com on 31 May 2012 at 11:11