当前位置: 首页>>代码示例>>Python>>正文


Python QNetworkRequest.setRawHeader方法代码示例

本文整理汇总了Python中PyQt5.QtNetwork.QNetworkRequest.setRawHeader方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkRequest.setRawHeader方法的具体用法?Python QNetworkRequest.setRawHeader怎么用?Python QNetworkRequest.setRawHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtNetwork.QNetworkRequest的用法示例。


在下文中一共展示了QNetworkRequest.setRawHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def send(params):
     url = self.formatUrl(endpoint, params)
     request = QNetworkRequest(url)
     headers['User-Agent'] = 'Divi QGIS Plugin/%s' % PLUGIN_VERSION
     QgsMessageLog.logMessage(str(headers), 'DIVI')
     for key, value in headers.items():
         request.setRawHeader(key.encode('utf-8'), value.encode('utf-8'))
     if method == 'delete':
         reply = manager.sendCustomRequest(request, 'DELETE'.encode('utf-8'), data)
     else:
         if not data:
             reply = getattr(manager, method)(request)
         elif isinstance(data, QHttpMultiPart) == True:
             reply = getattr(manager, method)(request, data)
         elif isinstance(data, str) == True:
             reply = getattr(manager, method)(request, data.encode('utf-8'))
     loop = QEventLoop()
     reply.uploadProgress.connect(self.uploadProgress)
     reply.downloadProgress.connect(self.downloadProgress)
     reply.metaDataChanged.connect(self.metaDataChanged)
     #reply.error.connect(self._error)
     reply.finished.connect(loop.exit)
     self.abort_sig.connect( reply.abort )
     loop.exec_()
     self.abort_sig.disconnect( reply.abort )
     return reply
开发者ID:gis-support,项目名称:DIVI-QGIS-Plugin,代码行数:28,代码来源:connector.py

示例2: _createRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def _createRequest(self, url: str, basic_auth_username: str = "", basic_auth_password: str = "") -> QNetworkRequest:
     request = QNetworkRequest(url)
     request.setRawHeader("User-Agent".encode(), self._user_agent)
     if basic_auth_username and basic_auth_password:
         data = base64.b64encode(("%s:%s" % (basic_auth_username, basic_auth_password)).encode()).decode("utf-8")
         request.setRawHeader("Authorization".encode(), ("Basic %s" % data).encode())
     return request
开发者ID:fieldOfView,项目名称:OctoPrintPlugin,代码行数:9,代码来源:DiscoverOctoPrintAction.py

示例3: _makeRequestByType

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def _makeRequestByType(self, request_type: str) -> None:
     Logger.log("i", "Requesting %s metadata from server.", request_type)
     request = QNetworkRequest(self._request_urls[request_type])
     for header_name, header_value in self._request_headers:
         request.setRawHeader(header_name, header_value)
     if self._network_manager:
         self._network_manager.get(request)
开发者ID:rwreynolds,项目名称:Cura,代码行数:9,代码来源:Toolbox.py

示例4: _createEmptyRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def _createEmptyRequest(self, path: str, content_type: Optional[str] = "application/json") -> QNetworkRequest:
     request = QNetworkRequest(QUrl(path))
     if content_type:
         request.setHeader(QNetworkRequest.ContentTypeHeader, content_type)
     access_token = self._account.accessToken
     if access_token:
         request.setRawHeader(b"Authorization", "Bearer {}".format(access_token).encode())
     return request
开发者ID:TinkerGnome,项目名称:Cura,代码行数:10,代码来源:CloudApiClient.py

示例5: _getRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def _getRequest(self, url):
     request = QNetworkRequest(QUrl(url))
     # key
     request.setRawHeader(b"Key", b"")
     # request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
     # request.setRawHeader("Accept-Encoding", "gzip, deflate, sdch")
     # request.setRawHeader("Accept-Language", "zh-CN,zh;q=0.8")
     # header
     request.setHeader(QNetworkRequest.ContentTypeHeader, "application/octet-stream")
     # user agent
     request.setHeader(QNetworkRequest.UserAgentHeader, "Blog/Mzone 1.0")
     return request
开发者ID:892768447,项目名称:BlogClient,代码行数:14,代码来源:httputils.py

示例6: _load_content

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
    def _load_content(self, content_type, content):
        """
        This method is for displaying some content of
        such types: local web pages, remote web pages,
        local pdf`s, local videos.

        It should be called like in the following example
        to work correctly:
        self._load_content('local_video', 'some_video.mp4')
        """
        self._main_browser_reset_zoom()  # reset zoom
        if content_type == 'local_url':
            source = config['flask_server_home'] + \
                config['flask_server_local_page_client'] + \
                content  # simply get the file from flask-server by its relative path-id
            # specify type of currently opened file for zoom and scroll methods
            self._cur_filetype = "webpage"
        elif content_type == 'external_url':
            self._cur_filetype = "webpage"
            # no needs required as, link should be given in
            # 'http://yoursite.com/yourpage'
            source = content
        elif content_type == 'local_pdf':
            # to render PDF`s we use PDF.js, so we open its page and send it a
            # path for the target file.
            source = config['flask_server_home'] + \
                config['flask_server_local_page_client'] + \
                content
            self._cur_filetype = "pdf"
        elif content_type == 'local_video':
            # in case of opening local videos we need to modify the path to the video in the source code of
            # the videoplayer, so don`t die after reading this code. It works just in the same style as other
            # filetypes, but in a very weird way.
            source = config['flask_server_home'] + \
                config['flask_server_video_addr_client'] + content
            logger.info('Opening video at {}'.format(source))
            self._cur_filetype = "video"
        # Set a custom user agent to avoid message about deprecated version of
        # browser

        self._main_browser.page().userAgentForUrl = self._custom_ua

        logger.info('Loading data on address: {}'.format(source))

        # Create a request to be able to set user-agent data. Without
        # it, it`s impossible to customize request data.
        request = QNetworkRequest()
        request.setUrl(QUrl(source))
        request.setRawHeader("USER-AGENT", config['output_user_agent'])

        # and finally load the result
        self._main_browser.load(request)
开发者ID:TarasZelyk,项目名称:ariusproject,代码行数:54,代码来源:output_main.py

示例7: junk

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
def junk(app):
    userapi = "https://api.gitter.im/v1/user"
    roomapi = "https://api.gitter.im/v1/rooms/{}/rooms"
    streamapi = 'https://stream.gitter.im/v1/rooms/{}/chatMessages'
    
    userurl = QUrl(userapi)
    #roomsurl = QUrl(roomapi.format(user_id))
    #encoded = QUrl(streamapi.format(encoded_id))
    req = QNetworkRequest(userurl)
    req.setRawHeader("Accept", "application/json")
    req.setRawHeader("Authorization", 'Bearer '+token)
    resp = app.net.get(req)
    resp.readyRead.connect(lambda : viewresp(resp))
开发者ID:detrout,项目名称:telepathy-gitter,代码行数:15,代码来源:gitter.py

示例8: _doGet

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
	def _doGet(self, path):
		url = urlunsplit(('http', self.addr, path, '', ''))
		sig = self._sign(b'GET', path.encode('utf-8'), b'')
		headers = {
			HMAC_HEADER: b64encode(sig)
		}

		request = QNetworkRequest(QUrl(url))
		for hname in headers:
			request.setRawHeader(hname, headers[hname])

		reply = self.network.get(request)
		return reply
开发者ID:hydrargyrum,项目名称:eye,代码行数:15,代码来源:daemon.py

示例9: __tabContextMenuClone

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def __tabContextMenuClone(self):
     """
     Private method to clone the selected tab.
     """
     idx = self.__tabContextMenuIndex
     if idx < 0:
         idx = self.currentIndex()
     if idx < 0 or idx > self.count():
         return
     
     req = QNetworkRequest(self.widget(idx).url())
     req.setRawHeader(b"X-Eric6-UserLoadAction", b"1")
     self.newBrowser(None, (req, QNetworkAccessManager.GetOperation, b""))
开发者ID:testmana2,项目名称:test,代码行数:15,代码来源:HelpTabWidget.py

示例10: _doPost

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
	def _doPost(self, path, **params):
		url = urlunsplit(('http', self.addr, path, '', ''))
		body = json.dumps(params)
		sig = self._sign(b'POST', path.encode('utf-8'), body.encode('utf-8'))
		headers = {
			HMAC_HEADER: b64encode(sig),
			'Content-Type': 'application/json'
		}

		request = QNetworkRequest(QUrl(url))
		for hname in headers:
			request.setRawHeader(hname, headers[hname])
		reply = self.network.post(request, body)
		return reply
开发者ID:hydrargyrum,项目名称:eye,代码行数:16,代码来源:daemon.py

示例11: __lineEditReturnPressed

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
 def __lineEditReturnPressed(self):
     """
     Private slot to handle the entering of an URL.
     """
     edit = self.sender()
     url = self.__guessUrlFromPath(edit.text())
     request = QNetworkRequest(url)
     request.setRawHeader(b"X-Eric6-UserLoadAction", b"1")
     if e5App().keyboardModifiers() == Qt.AltModifier:
         self.newBrowser(
             None, (request, QNetworkAccessManager.GetOperation, b""))
     else:
         self.currentBrowser().setSource(
             None, (request, QNetworkAccessManager.GetOperation, b""))
         self.currentBrowser().setFocus()
开发者ID:testmana2,项目名称:test,代码行数:17,代码来源:HelpTabWidget.py

示例12: request_obj

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
    def request_obj(self, url, headers=None, body=None):
        """ Return a QNetworkRequest object """
        request = QNetworkRequest()
        request.setUrl(to_qurl(url))
        request.setOriginatingObject(self.web_page.mainFrame())

        if headers is not None:
            self.web_page.skip_custom_headers = True
            self._set_request_headers(request, headers)

        if body and not request.hasRawHeader(b"content-type"):
            # there is POST body but no content-type
            # QT will set this header, but it will complain so better to do this here
            request.setRawHeader(b"content-type", b"application/x-www-form-urlencoded")

        return request
开发者ID:takaaptech,项目名称:splash,代码行数:18,代码来源:browser_tab.py

示例13: DownloadManager

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
class DownloadManager(QNetworkAccessManager):
    def __init__(self, parent=None):
        super().__init__(parent)


    def addUrl(self, url):
        print(url)
        self.request = QNetworkRequest(QUrl(url))
        self.request.setRawHeader(b"User-Agent", b"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1")

        self.reply = self.get(self.request)

        self.reply.downloadProgress.connect(self.setProgress)

        return self.request

    def setProgress(self, a, s):
        print(a, s)
开发者ID:mthnzbk,项目名称:pisi-player,代码行数:20,代码来源:downloadmanager.py

示例14: downloadBinPackage

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
def downloadBinPackage(packageUrl, destinationFileName):
    request = QNetworkRequest(QUrl(packageUrl))
    request.setRawHeader(b'Accept-Encoding', b'gzip,deflate')

    reply = QgsNetworkAccessManager.instance().get(request)
    evloop = QEventLoop()
    reply.finished.connect(evloop.quit)
    evloop.exec_(QEventLoop.ExcludeUserInputEvents)
    content_type = reply.rawHeader(b'Content-Type')
    if content_type == b'application/zip':
        if os.path.isfile(destinationFileName):
            os.unlink(destinationFileName)

        destinationFile = open(destinationFileName, 'wb')
        destinationFile.write(bytearray(reply.readAll()))
        destinationFile.close()
    else:
        ret_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
        raise IOError("{} {}".format(ret_code, packageUrl))
开发者ID:lutraconsulting,项目名称:qgis-crayfish-plugin,代码行数:21,代码来源:install_helper.py

示例15: download

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setRawHeader [as 别名]
    def download(self):
        grab = None
        for x in range(self._tilesRect.width()):
            for y in range(self._tilesRect.height()):
                tp = Point(self._tilesRect.topLeft() + QPoint(x, y))
                if tp not in self._tilePixmaps:
                    grab = QPoint(tp)
                    break

        if grab is None:
            self._url = QUrl()
            return

        path = 'http://tile.openstreetmap.org/%d/%d/%d.png' % (self.zoom, grab.x(), grab.y())
        self._url = QUrl(path)
        request = QNetworkRequest()
        request.setUrl(self._url)
        request.setRawHeader(b'User-Agent', b'Nokia (PyQt) Graphics Dojo 1.0')
        request.setAttribute(QNetworkRequest.User, grab)
        self._manager.get(request)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:22,代码来源:lightmaps.py


注:本文中的PyQt5.QtNetwork.QNetworkRequest.setRawHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。