From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Thierry Leurent Newsgroups: gmane.emacs.help Subject: How to send a request to a Website. Date: Thu, 20 Apr 2017 12:59:28 +0200 Message-ID: <2320801.DznD1DNTWb@e6430> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: blaine.gmane.org 1492686007 308 195.159.176.226 (20 Apr 2017 11:00:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Apr 2017 11:00:07 +0000 (UTC) User-Agent: KMail/5.2.3 (Linux/4.9.0-2-amd64; KDE/5.28.0; x86_64; ; ) To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 20 13:00:01 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d19oe-0008La-Ol for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Apr 2017 13:00:00 +0200 Original-Received: from localhost ([::1]:52946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d19ok-0003jm-J4 for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Apr 2017 07:00:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d19oK-0003iD-DQ for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 06:59:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d19oH-00024c-As for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 06:59:40 -0400 Original-Received: from 17.mo3.mail-out.ovh.net ([87.98.178.58]:50177) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d19oH-000245-4j for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 06:59:37 -0400 Original-Received: from player758.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 74640C7FC4 for ; Thu, 20 Apr 2017 12:59:34 +0200 (CEST) Original-Received: from e6430.localnet (200.27-200-80.adsl-dyn.isp.belgacom.be [80.200.27.200]) (Authenticated sender: thierry.leurent@asgardian.be) by player758.ha.ovh.net (Postfix) with ESMTPSA id 063172C008E for ; Thu, 20 Apr 2017 12:59:33 +0200 (CEST) X-Ovh-Tracer-Id: 10706745165755593686 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeliedrfedvgdefgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.178.58 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112816 Archived-At: Hello, Hello, I'm working on a way to post article to a WordPress blog using OAuth2. I'm able to retrieve the OAuth2 token but I cannot publish a post using Emacs. I'm not allowed, why ???? I don't know but I can do it using Python so I would like understant what append. Thank. Thierry Emacs' Code --------------- (require 'url) (require 'url-http) (require 'json) (defvar user-data (with-current-buffer (progn (url-request-method "POST") (url-request-extra-headers `(("Content-Type" . "application/x-www-form- urlencoded") ("Authorization" . "bearer 1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt"))) (url-request-data (json-encode '(:title "Post using emacs."))) (url-retrieve-synchronously "https://asgardian.be/WordPress/wp-json/wp/v2/ posts?state=1234&access_token=1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt") ) (goto-char url-http-end-of-headers) (json-read) )) (message "DBG - Result : %s " user-data) DBG - Result : ((code . rest_cannot_create) (message . Sorry, you are not allowed to create posts as this user.) (data (status . 401))) Python's code ------------------- import urllib import httplib2 import pprint http = httplib2.Http() url = 'https://asgardian.be/WordPress/wp-json/wp/v2/posts? state=1234&access_token=1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt' headers = {'Content-type': 'application/x-www-form-urlencoded', 'Authorization': 'bearer 1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt'} body = {"title":"New post using emacs and python"} response, content = http.requestb(url, 'POST', headers=headers, body=urllib.urlencode(body)) print(" Content : {}" .format(content)) -- Thierry Leurent