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


Python QNetworkRequest.setHeader方法代码示例

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


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

示例1: _createEmptyRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
 def _createEmptyRequest(self, target: str, content_type: Optional[str] = "application/json") -> QNetworkRequest:
     url = QUrl("http://" + self._address + self._api_prefix + target)
     request = QNetworkRequest(url)
     if content_type is not None:
         request.setHeader(QNetworkRequest.ContentTypeHeader, content_type)
     request.setHeader(QNetworkRequest.UserAgentHeader, self._user_agent)
     return request
开发者ID:Ultimaker,项目名称:Cura,代码行数:9,代码来源:NetworkedPrinterOutputDevice.py

示例2: _createEmptyRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [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

示例3: perform_put

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
    def perform_put(self, endpoint, data, url):
        """
        Perform an HTTP PUT request.

        :param endpoint: the name of the Tribler endpoint.
        :param data: the data/body to send with the request.
        :param url: the url to send the request to.
        """
        request = QNetworkRequest(QUrl(url))
        request.setHeader(QNetworkRequest.ContentTypeHeader, "application/x-www-form-urlencoded")
        reply = self.put(request, data)
        return reply
开发者ID:synctext,项目名称:tribler,代码行数:14,代码来源:tribler_request_manager.py

示例4: _getRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [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

示例5: post

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
 def post(self, url, param=None, data=None, json=True):
     if isinstance(data, dict):
         f = ''
         for i in data:
             f += '{}={}&'.format(i, data[i])
         data = f[:-1]
     byte_data = QtCore.QByteArray()
     byte_data.append(data)
     url = QtCore.QUrl(parse_url(url, param))
     request = QNetworkRequest(url)
     if json:
         request.setHeader(QNetworkRequest.ContentTypeHeader, 'application/json')
     reply = self.session.post(request, byte_data)
     return reply
开发者ID:rui19921122,项目名称:MeetingsDesktop_v2,代码行数:16,代码来源:request.py

示例6: getSearchRequestData

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
 def getSearchRequestData(cls, term):
     """
     Class method to assemble the search request data structure.
     
     @param term search term (string)
     @return tuple of network request object, operation and parameters
         (QNetworkRequest, QNetworkAccessManager.Operation, QByteArray)
     """
     request = QNetworkRequest(QUrl(cls.SearchUrl))
     request.setHeader(QNetworkRequest.ContentTypeHeader,
                       "application/x-www-form-urlencoded")
     op = QNetworkAccessManager.PostOperation
     params = QByteArray("chain=").append(QUrl.toPercentEncoding(term))
     
     return (request, op, params)
开发者ID:Darriall,项目名称:eric,代码行数:17,代码来源:VirusTotalApi.py

示例7: _setJobState

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
    def _setJobState(self, job_state):
        if not self._selected_printer:
            return

        selected_printer_uuid = self._printers_dict[self._selected_printer["unique_name"]]["uuid"]
        if selected_printer_uuid not in self._print_job_by_printer_uuid:
            return

        print_job_uuid = self._print_job_by_printer_uuid[selected_printer_uuid]["uuid"]

        url = QUrl(self._api_base_uri + "print_jobs/" + print_job_uuid + "/action")
        put_request = QNetworkRequest(url)
        put_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
        data = '{"action": "' + job_state + '"}'
        self._manager.put(put_request, data.encode())
开发者ID:olemis,项目名称:Cura,代码行数:17,代码来源:NetworkClusterPrinterOutputDevice.py

示例8: __getFileScanReportUrl

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
 def __getFileScanReportUrl(self, scanId):
     """
     Private method to get the report URL for a file scan.
     
     @param scanId ID of the scan to get the report URL for (string)
     """
     request = QNetworkRequest(QUrl(self.GetUrlReportUrl))
     request.setHeader(QNetworkRequest.ContentTypeHeader,
                       "application/x-www-form-urlencoded")
     params = QByteArray("key={0}&resource={1}".format(
         Preferences.getHelp("VirusTotalServiceKey"), scanId))
     
     import Helpviewer.HelpWindow
     nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()
     reply = nam.post(request, params)
     reply.finished.connect(self.__getFileScanReportUrlFinished)
     self.__replies.append(reply)
开发者ID:Darriall,项目名称:eric,代码行数:19,代码来源:VirusTotalApi.py

示例9: submitUrl

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
 def submitUrl(self, url):
     """
     Public method to submit an URL to be scanned.
     
     @param url url to be scanned (QUrl)
     """
     request = QNetworkRequest(QUrl(self.ScanUrlUrl))
     request.setHeader(QNetworkRequest.ContentTypeHeader,
                       "application/x-www-form-urlencoded")
     params = QByteArray("key={0}&url=".format(
         Preferences.getHelp("VirusTotalServiceKey")))\
         .append(QUrl.toPercentEncoding(url.toString()))
     
     import Helpviewer.HelpWindow
     nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()
     reply = nam.post(request, params)
     reply.finished.connect(self.__submitUrlFinished)
     self.__replies.append(reply)
开发者ID:Darriall,项目名称:eric,代码行数:20,代码来源:VirusTotalApi.py

示例10: get

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
    def get(self, url, *, user_agent=None, **kwargs):
        """Start a download with a link URL.

        Args:
            url: The URL to get, as QUrl
            user_agent: The UA to set for the request, or None.
            **kwargs: passed to get_request().

        Return:
            The created DownloadItem.
        """
        if not url.isValid():
            urlutils.invalid_url_error(url, "start download")
            return None
        req = QNetworkRequest(url)
        if user_agent is not None:
            req.setHeader(QNetworkRequest.UserAgentHeader, user_agent)
        return self.get_request(req, **kwargs)
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:20,代码来源:qtnetworkdownloads.py

示例11: checkServiceKeyValidity

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
 def checkServiceKeyValidity(self, key, protocol=""):
     """
     Public method to check the validity of the given service key.
     
     @param key service key (string)
     @param protocol protocol used to access VirusTotal (string)
     """
     if protocol == "":
         urlStr = self.GetFileReportUrl
     else:
         urlStr = self.GetFileReportPattern.format(protocol)
     request = QNetworkRequest(QUrl(urlStr))
     request.setHeader(QNetworkRequest.ContentTypeHeader,
                       "application/x-www-form-urlencoded")
     params = QByteArray("key={0}&resource={1}".format(
         key, self.TestServiceKeyScanID))
     
     import Helpviewer.HelpWindow
     nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()
     reply = nam.post(request, params)
     reply.finished.connect(self.__checkServiceKeyValidityFinished)
     self.__replies.append(reply)
开发者ID:Darriall,项目名称:eric,代码行数:24,代码来源:VirusTotalApi.py

示例12: ForRec

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply, QSslConfiguration, QSsl
from PyQt5.QtCore import QUrl


class ForRec(QNetworkAccessManager):
	def Reqest(self,reply):
		print(reply.readAll())
   

if __name__ == '__main__':

	url = "https://api.telegram.org/bot"

	manager = QNetworkAccessManager()
	request = QNetworkRequest()

	config = QSslConfiguration.defaultConfiguration()
	config.setProtocol(QSsl.SecureProtocols)

	request.setSslConfiguration(config)
	request.setUrl(QUrl(url));
	request.setHeader(QNetworkRequest.ServerHeader, "getUpdates")

	#manager.get(request)




开发者ID:iphizic,项目名称:PyTeleBot,代码行数:26,代码来源:main.py

示例13: E5XmlRpcClient

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]
class E5XmlRpcClient(QObject):
    """
    Class implementing a xmlrpc client for Qt.
    """
    def __init__(self, url, parent=None):
        """
        Constructor
        
        @param url xmlrpc handler URL (string or QUrl)
        @param parent parent object (QObject)
        """
        super(E5XmlRpcClient, self).__init__(parent)
        
        # attributes for the network objects
        self.__networkManager = QNetworkAccessManager(self)
        self.__networkManager.proxyAuthenticationRequired.connect(
            proxyAuthenticationRequired)
        self.__networkManager.finished.connect(self.__replyFinished)
        if SSL_AVAILABLE:
            self.__sslErrorHandler = E5SslErrorHandler(self)
            self.__networkManager.sslErrors.connect(self.__sslErrors)
        
        self.__callmap = {}
        
        self.__request = QNetworkRequest(QUrl(url))
        self.__request.setRawHeader(b"User-Agent", b"E5XmlRpcClient/1.0")
        self.__request.setHeader(QNetworkRequest.ContentTypeHeader, "text/xml")
    
    def setUrl(self, url):
        """
        Public slot to set the xmlrpc handler URL.
        
        @param url xmlrpc handler URL (string or QUrl)
        """
        url = QUrl(url)
        if url.isValid():
            self.__request.setUrl(url)
    
    def call(self, method, args, responseCallback, errorCallback):
        """
        Public method to call the remote server.
        
        @param method name of the remote method to be called (string)
        @param args tuple of method arguments (tuple)
        @param responseCallback method to be called with the returned
            result as a tuple (function)
        @param errorCallback method to be called in case of an error
            with error code and error string (function)
        """
        assert isinstance(args, tuple), \
            "argument must be tuple or Fault instance"
        
        data = xmlrpc.dumps(args, method).encode("utf-8")
        reply = self.__networkManager.post(
            self.__request, QByteArray(data))
        self.__callmap[reply] = (responseCallback, errorCallback)
    
    def abort(self):
        """
        Public method to abort all calls.
        """
        for reply in list(self.__callmap):
            if reply.isRunning():
                reply.abort()
    
    def __sslErrors(self, reply, errors):
        """
        Private slot to handle SSL errors.
        
        @param reply reference to the reply object (QNetworkReply)
        @param errors list of SSL errors (list of QSslError)
        """
        ignored = self.__sslErrorHandler.sslErrorsReply(reply, errors)[0]
        if ignored == E5SslErrorHandler.NotIgnored and reply in self.__callmap:
            self.__callmap[reply][1](xmlrpc.TRANSPORT_ERROR, self.tr(
                "SSL Error"))
    
    def __replyFinished(self, reply):
        """
        Private slot handling the receipt of a reply.
        
        @param reply reference to the finished reply (QNetworkReply)
        """
        if reply not in self.__callmap:
            return
        
        if reply.error() != QNetworkReply.NoError:
            self.__callmap[reply][1](xmlrpc.TRANSPORT_ERROR,
                                     reply.errorString())
        else:
            data = bytes(reply.readAll()).decode("utf-8")
            try:
                data = xmlrpc.loads(data)[0]
                self.__callmap[reply][0](data)
            except xmlrpc.Fault as fault:
                self.__callmap[reply][1](fault.faultCode, fault.faultString)
        
        reply.deleteLater()
        del self.__callmap[reply]
开发者ID:pycom,项目名称:EricShort,代码行数:101,代码来源:E5XmlRpcClient.py

示例14: OctoPrintOutputDevice

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setHeader [as 别名]

#.........这里部分代码省略.........

    def requestWrite(self, node, file_name = None, filter_by_machine = False):
        self._gcode = getattr(Application.getInstance().getController().getScene(), "gcode_list")

        self.startPrint()

    def isConnected(self):
        return self._connection_state != ConnectionState.closed and self._connection_state != ConnectionState.error

    ##  Start requesting data from printer
    def connect(self):
        self.setConnectionState(ConnectionState.connecting)
        self._update()  # Manually trigger the first update, as we don't want to wait a few secs before it starts.
        self._update_camera()
        Logger.log("d", "Connection with printer %s with ip %s started", self._key, self._address)
        self._update_timer.start()
        self._camera_timer.start()

    newImage = pyqtSignal()

    @pyqtProperty(QUrl, notify = newImage)
    def cameraImage(self):
        self._camera_image_id += 1
        temp = "image://camera/" + str(self._camera_image_id)
        return QUrl(temp, QUrl.TolerantMode)

    def getCameraImage(self):
        return self._camera_image

    def _setJobState(self, job_state):
        url = QUrl("http://" + self._address + self._api_prefix + "job")
        self._job_request = QNetworkRequest(url)
        self._job_request.setRawHeader(self._api_header.encode(), self._api_key.encode())
        self._job_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
        if job_state == "abort":
            command = "cancel"
        elif job_state == "print":
            if self.jobState == "paused":
                command = "pause"
            else:
                command = "start"
        elif job_state == "pause":
            command = "pause"
        data = "{\"command\": \"%s\"}" % command
        self._job_reply = self._manager.post(self._job_request, data.encode())
        Logger.log("d", "Sent command to OctoPrint instance: %s", data)

    def startPrint(self):
        if self.jobState != "ready" and self.jobState != "":
            self._error_message = Message(i18n_catalog.i18nc("@info:status", "Printer is printing. Unable to start a new job."))
            self._error_message.show()
            return
        try:
            self._progress_message = Message(i18n_catalog.i18nc("@info:status", "Sending data to printer"), 0, False, -1)
            self._progress_message.show()

            ## Mash the data into single string
            single_string_file_data = ""
            for line in self._gcode:
                single_string_file_data += line

            ##  TODO: Use correct file name (we use placeholder now)
            file_name = "%s.gcode" % Application.getInstance().getPrintInformation().jobName

            ##  Create multi_part request
            self._post_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType)
开发者ID:SHINOTECH,项目名称:OctoPrintPlugin,代码行数:70,代码来源:OctoPrintOutputDevice.py


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