Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google应用程序引擎-使用URLFetch进行基本Cookie处理_Python_Google App Engine_Cookies_Webapp2_Urlfetch - Fatal编程技术网

Python Google应用程序引擎-使用URLFetch进行基本Cookie处理

Python Google应用程序引擎-使用URLFetch进行基本Cookie处理,python,google-app-engine,cookies,webapp2,urlfetch,Python,Google App Engine,Cookies,Webapp2,Urlfetch,专家们 看来,使用谷歌应用程序引擎检索最基本的网站也是相当有挑战性的 在我的情况下,我希望通过以下url检索网站: 我想接受所有cookies,然后向此url发布响应(这是一个简单的表单帖子): 我想发布的字符串是: 'POSTDATA': 'Q585=1&Q2926=1&Q586=200000&Q587=240000&Q588=&Q9166=07071&Q591=1&Q592=1&Q594=3&searchButton

专家们

看来,使用谷歌应用程序引擎检索最基本的网站也是相当有挑战性的

在我的情况下,我希望通过以下url检索网站:

我想接受所有cookies,然后向此url发布响应(这是一个简单的表单帖子):

我想发布的字符串是:

'POSTDATA': 'Q585=1&Q2926=1&Q586=200000&Q587=240000&Q588=&Q9166=07071&Q591=1&Q592=1&Q594=3&searchButton=Search'
我遇到的问题是,该网页声明在我的web浏览器上“未启用Cookie”

正如您从下面的代码中所看到的,我尝试手动添加cookies,但是没有成功

请帮忙! -托德

yaml文件:

application: fimrates
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: fimrates.app

实际上,您并不是在用代码设置cookie。这是您的代码的修订版本

#import this module to be able to create a cookie
import Cookie

class BankHandler(webapp2.RequestHandler):

    #put this function to create the cookie header
    def createCookieHeader(self, cookie):
        cookieHeader = ""
        for value in cookie.values():
            cookieHeader += "%s=%s; " % (value.key, value.value)
        return cookieHeader

    def get(self):
        ...
        self.cookie = Cookie.SimpleCookie() #create the cookie

        result = urlfetch.fetch({...,
                       #inject the cookie header                                                 
                      'Cookie': self.createCookieHeader(self.cookie)})

        cookie = result.headers.get('set-cookie', '')
        input_text = {...}

        #the header is 'Cookie' 
        input_text['Cookie'] = cookie

        url2 = "http://tdbank.mortgagewebcenter.com/PowerSite/CheckRates.aspx/Search"
        result2 = urlfetch.fetch(url2, method='POST',headers=input_text)
        ...
#import this module to be able to create a cookie
import Cookie

class BankHandler(webapp2.RequestHandler):

    #put this function to create the cookie header
    def createCookieHeader(self, cookie):
        cookieHeader = ""
        for value in cookie.values():
            cookieHeader += "%s=%s; " % (value.key, value.value)
        return cookieHeader

    def get(self):
        ...
        self.cookie = Cookie.SimpleCookie() #create the cookie

        result = urlfetch.fetch({...,
                       #inject the cookie header                                                 
                      'Cookie': self.createCookieHeader(self.cookie)})

        cookie = result.headers.get('set-cookie', '')
        input_text = {...}

        #the header is 'Cookie' 
        input_text['Cookie'] = cookie

        url2 = "http://tdbank.mortgagewebcenter.com/PowerSite/CheckRates.aspx/Search"
        result2 = urlfetch.fetch(url2, method='POST',headers=input_text)
        ...