0

Here is my situation: I have created a QWebview, loaded a Youtube page, and logged in. I select upload option (http://www.youtube.com/my_videos_upload), and choose a video to upload. However, youtube always returns

"The server has returned an invalid response. Please follow these steps and try uploading the file again."

How can I solve that problem? Thanks.

EDIT: the code I'm using is:

import sys
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebView
from PyQt4.QtNetwork import QNetworkAccessManager
from PyQt4 import QtCore

def fillForm(web, username, password):
    print "Filling in the form"
    doc = web.page().mainFrame().documentElement()

    print "Finding username tag"
    user = doc.findFirst("input[id=Email]")
    print "Finding passwd tag"
    passwd = doc.findFirst("input[id=Passwd]")    

    print "Setting information"
    user.evaluateJavaScript("this.value = '%s'" % username)
    passwd.evaluateJavaScript("this.value = '%s'" % password)    
    button = doc.findFirst("input[id=signIn]")
    button.evaluateJavaScript("this.click()")

def doLogin(web, url, username, password):        
    web.loadFinished.connect(lambda: fillForm(web, username, password))
    web.load(url)
    web.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    nam = QNetworkAccessManager()
    web = QWebView()
    web.page().setNetworkAccessManager(nam)
    url = QUrl(r"https://accounts.google.com/Login")
    username = "name"
    password = "pass"
    doLogin(web, url, username, password)
    app.exec_()

1 Answers1

0

Try adding this after web = QWebView():

settings = web.settings()
settings.setAttribute(QWebSettings.PluginsEnabled, True)
  • you might add `from PyQt4.QtWebKit import QWebView, QWebSettings` –  Dec 08 '12 at 14:32
  • May be that is a problem with QWebview? Google says we should use a 'modern' browser: https://support.google.com/youtube/bin/answer.py?hl=en&answer=166815&hl=en-US – user1865009 Dec 08 '12 at 14:45
  • The link 'following the steps' leads me to the page above (https://support.google.com/youtube/bin/answer.py?hl=en&answer=166815&hl=en-US). – user1865009 Dec 08 '12 at 14:56
  • I think I will use Youtube Python ApI instead, though it would be better if I can use web interface. – user1865009 Dec 08 '12 at 14:58
  • Ok, never mind. I modified the code at http://code.google.com/p/gdata-python-client/source/browse/tests/gdata_tests/youtube/service_test.py and it works perfectly! – user1865009 Dec 14 '12 at 05:12