def test3(self): url = QUrl("http://localhost:18080/user") query = QUrlQuery() query.addQueryItem("username", "yqfcpy"); query.addQueryItem("password", "111111"); url.setQuery(query.query()) print(query.query()) print(url)
def exchange_authorization_code(self, authorization_code, scopes, callback): log.debug( "OAuth: exchanging authorization_code %s for an access_token", authorization_code) path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "authorization_code") url_query.addQueryItem("code", authorization_code) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url_query.addQueryItem("redirect_uri", "urn:ietf:wg:oauth:2.0:oob") url.setQuery(url_query.query(QUrl.FullyEncoded)) data = url.query() self.webservice.post( self.host, self.port, path, data, partial(self.on_exchange_authorization_code_finished, scopes, callback), mblogin=True, priority=True, important=True, request_mimetype="application/x-www-form-urlencoded")
def getRemoteTiles(self): query = QUrlQuery() url = QUrl(f"{self.url}/search") query.addQueryItem("q", self.search_str) query.addQueryItem("f", "pjson") url.setQuery(query.query()) response = QgsNetworkAccessManager.blockingGet( QNetworkRequest(QUrl(url))) if response.error() != QNetworkReply.NoError: raise Exception(response.errorString()) responsejson = json.loads(response.content().data()) LOG.debug("response from data repository: %s" % responsejson) tiles = [] for result in responsejson["results"]: itemid = result["id"] timestamp = self.dataTimestamp(itemid) if timestamp is None: status = self.NOT_INSTALLED elif timestamp < result["modified"]: status = self.UPDATABLE else: status = self.UP_TO_DATE tile = dict(result) tile["status"] = status tiles.append(tile) return tiles
def refresh_access_token(self, callback): refresh_token = config.persist["oauth_refresh_token"] log.debug("OAuth: refreshing access_token with a refresh_token %s", refresh_token) host, port = config.setting['server_host'], config.setting[ 'server_port'] path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "refresh_token") url_query.addQueryItem("refresh_token", refresh_token) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url.setQuery(url_query.query(QUrl.FullyEncoded)) data = string_(url.query()) self.xmlws.post(host, port, path, data, partial(self.on_refresh_access_token_finished, callback), xml=False, mblogin=True, priority=True, important=True)
def exchange_authorization_code(self, authorization_code, scopes, callback): log.debug( "OAuth: exchanging authorization_code %s for an access_token", authorization_code) host, port = config.setting['server_host'], config.setting[ 'server_port'] path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "authorization_code") url_query.addQueryItem("code", authorization_code) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url_query.addQueryItem("redirect_uri", "urn:ietf:wg:oauth:2.0:oob") url.setQuery(url_query.query(QUrl.FullyEncoded)) data = string_(url.query()) self.xmlws.post(host, port, path, data, partial(self.on_exchange_authorization_code_finished, scopes, callback), xml=False, mblogin=True, priority=True, important=True)
def get(self, url: str, param: dict = None): # 创建一个请求 path = QUrl(url) if param != None: query = QUrlQuery() for item in param.items(): query.addQueryItem(item[0], str(item[1])) path.setQuery(query.query()) req = QtNetwork.QNetworkRequest(path) self.nam = QtNetwork.QNetworkAccessManager() self.nam.finished.connect(self.handleResponse) # 使用get请求 如果有参数的话 写一个data 放到get里 self.nam.get(req)
def test6(self): a1 = 0.111111111111111111111111 b1 = 0.111111111111111111111111 print(a1 + b1) return None dic = {"username": "******", "password": 123456} path = QUrl("http://localhost:18080/user") query = QUrlQuery() if 1 != 2: for item in dic.items(): query.addQueryItem(item[0], item[1]) path.setQuery(query.query()) log.info(path)
def post(self, url: str, jsonBody: dict, param: dict = None): path = QUrl(url) sendData = QJsonDocument(jsonBody) if param != None: queryParams = QUrlQuery() for item in param.items(): queryParams.addQueryItem(item[0], str(item[1])) path.setQuery(queryParams.query()) req = QtNetwork.QNetworkRequest(path) # 设置头信息是json这里可以不写 # req.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, "application/json") self.nam = QtNetwork.QNetworkAccessManager() self.nam.finished.connect(self.handleResponse) self.nam.post(req, sendData.toJson())
def refresh_access_token(self, callback): refresh_token = config.persist["oauth_refresh_token"] log.debug("OAuth: refreshing access_token with a refresh_token %s", refresh_token) host, port = config.setting['server_host'], config.setting['server_port'] path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "refresh_token") url_query.addQueryItem("refresh_token", refresh_token) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url.setQuery(url_query.query(QUrl.FullyEncoded)) data = string_(url.query()) self.webservice.post(host, port, path, data, partial(self.on_refresh_access_token_finished, callback), parse_response_type=None, mblogin=True, priority=True, important=True)
def exchange_authorization_code(self, authorization_code, scopes, callback): log.debug("OAuth: exchanging authorization_code %s for an access_token", authorization_code) host, port = config.setting['server_host'], config.setting['server_port'] path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "authorization_code") url_query.addQueryItem("code", authorization_code) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url_query.addQueryItem("redirect_uri", "urn:ietf:wg:oauth:2.0:oob") url.setQuery(url_query.query(QUrl.FullyEncoded)) data = string_(url.query()) self.webservice.post(host, port, path, data, partial(self.on_exchange_authorization_code_finished, scopes, callback), parse_response_type=None, mblogin=True, priority=True, important=True)
def refresh_access_token(self, callback): log.debug("OAuth: refreshing access_token with a refresh_token %s", self.refresh_token) path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "refresh_token") url_query.addQueryItem("refresh_token", self.refresh_token) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url.setQuery(url_query.query(QUrl.FullyEncoded)) data = url.query() self.webservice.post( self.host, self.port, path, data, partial(self.on_refresh_access_token_finished, callback), mblogin=True, priority=True, important=True, request_mimetype="application/x-www-form-urlencoded")