request.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:pyload-requests 作者: pyload 项目源码 文件源码
def set_request_context(self, url, get, post,
                            referer, cookies, multipart=False):
        """
        Sets everything needed for the request.
        """
        url = safequote(url)

        if get:
            get = urlencode(get)
            url = "{0}?{1}".format(url, get)

        self.setopt(pycurl.URL, url)

        if post:
            self.setopt(pycurl.POST, 1)
            if not multipart:
                if isinstance(post, str):
                    post = convert.to_bytes(post, post)
                elif not isinstance(post, bytes):
                    post = safeurlencode(post)

                self.setopt(pycurl.POSTFIELDS, post)
            else:
                post = [(x, convert.to_bytes(y, y))
                        for x, y in post.items()]
                self.setopt(pycurl.HTTPPOST, post)
        else:
            self.setopt(pycurl.POST, 0)

        if referer and self.last_url:
            self.headers['Referer'] = str(self.last_url)
        else:
            self.headers['Referer'] = ""

        if cookies:
            for c in self.cj.output().splitlines():
                self.setopt(pycurl.COOKIELIST, c)
        else:
            # Magic string that erases all cookies
            self.setopt(pycurl.COOKIELIST, 'ALL')

        # TODO: remove auth again
        if "auth" in self.options:
            self.setopt(pycurl.USERPWD, self.options['auth'])

        self.setopt(pycurl.HTTPHEADER, self.headers.list())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号