emacs 25.1 で org2blogを使って WordPress に投稿するには

以前から気になっていた org2blog を emacs-25.1.1 で動かそう。 という話。


org2blog / README.org を参考に、packageから org2blog をインストールして、以下の様に設定。

(require 'org2blog-autoloads)
(setq org2blog/wp-blog-alist
      :url "http://***.somof.net/****"
      :username "****"
      :password "****"
      :wp-latex nil
      :wp-code t

早速試してみるとワーニングが出たので、追加で htmlize の新しいバージョンを手動でインストールした。



error in process sentinel: url-http-create-request: Multibyte text in HTTP request: POST /xmlrpc.php HTTP/1.1

error in process sentinel: Multibyte text in HTTP request: POST /xmlrpc.php HTTP/1.1

雰囲気、文字コードか改行コードの問題の様。 org2blogが呼び出している gzipコマンドを Apple製からGNU製に変えてみたけど、症状は変わらず。

仕方ないので org2blogのソースを追ってみたところ、エラーの発信源は emacsに添付されている url-http.el だった。 なんと、 emacs 自身のコード側に問題があったのだった。


;; Bug#23750
(unless (= (string-bytes request)
           (length request))
  (error "Multibyte text in HTTP request: %s" request))
(url-http-debug "Request is: \n%s" request)

今使っているemacsは、リリース版の emacs 25.1.1 なのだけど、たまたま出来たてのバグを踏んでしまったらしい。

request(XML-RPCのXMLそのもの)の文字数とバイト数が一致しない場合にエラーを返す、多分デバッグ用のコードなのだけど、 ユーザーには意味がないので、とりあえず削除することにする。


(advice-add 'url-http-create-request :override
(defun url-http-create-request-debug (&optional ref-url)
  "Create an HTTP request for <code>url-http-target-url', referred to by REF-URL."
  (let* ((extra-headers)
         (request nil)
         (no-cache (cdr-safe (assoc "Pragma" url-http-extra-headers)))
         (using-proxy url-http-proxy)
         (proxy-auth (if (or (cdr-safe (assoc "Proxy-Authorization"
                             (not using-proxy))
                       (let ((url-basic-auth-storage
                         (url-get-authentication url-http-proxy nil 'any nil))))
         (real-fname (url-filename url-http-target-url))
         (host (url-http--encode-string (url-host url-http-target-url)))
         (auth (if (cdr-safe (assoc "Authorization" url-http-extra-headers))
                 (url-get-authentication (or
                                          (and (boundp 'proxy-info)
                                          url-http-target-url) nil 'any nil))))
    (if (equal "" real-fname)
        (setq real-fname "/"))
    (setq no-cache (and no-cache (string-match "no-cache" no-cache)))
    (if auth
        (setq auth (concat "Authorization: " auth "\r\n")))
    (if proxy-auth
        (setq proxy-auth (concat "Proxy-Authorization: " proxy-auth "\r\n")))

    ;; Protection against stupid values in the referrer
    (if (and ref-url (stringp ref-url) (or (string= ref-url "file:nil")
                                           (string= ref-url "")))
        (setq ref-url nil))

    ;; We do not want to expose the referrer if the user is paranoid.
    (if (or (memq url-privacy-level '(low high paranoid))
            (and (listp url-privacy-level)
                 (memq 'lastloc url-privacy-level)))
        (setq ref-url nil))

    ;; url-http-extra-headers contains an assoc-list of
    ;; header/value pairs that we need to put into the request.
    (setq extra-headers (mapconcat
                         (lambda (x)
                           (concat (car x) ": " (cdr x)))
                         url-http-extra-headers "\r\n"))
    (if (not (equal extra-headers ""))
        (setq extra-headers (concat extra-headers "\r\n")))

    ;; This was done with a call to </code>format'.  Concatenating parts has
    ;; the advantage of keeping the parts of each header together and
    ;; allows us to elide null lines directly, at the cost of making
    ;; the layout less clear.
    (setq request
             ;; The request
             (or url-http-method "GET") " "
              (if using-proxy (url-recreate-url url-http-target-url) real-fname))
             " HTTP/" url-http-version "\r\n"
             ;; Version of MIME we speak
             "MIME-Version: 1.0\r\n"
             ;; (maybe) Try to keep the connection open
             "Connection: " (if (or using-proxy
                                    (not url-http-attempt-keepalives))
                                "close" "keep-alive") "\r\n"
                                ;; HTTP extensions we support
             (if url-extensions-header
                  "Extension: %s\r\n" url-extensions-header))
             ;; Who we want to talk to
             (if (/= (url-port url-http-target-url)
                      (url-type url-http-target-url) 'default-port))
                  "Host: %s:%d\r\n" host (url-port url-http-target-url))
               (format "Host: %s\r\n" host))
             ;; Who its from
             (if url-personal-mail-address
                  "From: " url-personal-mail-address "\r\n"))
             ;; Encodings we understand
             (if (or url-mime-encoding-string
                     ;; MS-Windows loads zlib dynamically, so recheck
                     ;; in case they made it available since
                     ;; initialization in url-vars.el.
                     (and (eq 'system-type 'windows-nt)
                          (fboundp 'zlib-available-p)
                          (setq url-mime-encoding-string "gzip")))
                  "Accept-encoding: " url-mime-encoding-string "\r\n"))
             (if url-mime-charset-string
                  "Accept-charset: "
                  (url-http--encode-string url-mime-charset-string)
             ;; Languages we understand
             (if url-mime-language-string
                  "Accept-language: " url-mime-language-string "\r\n"))
             ;; Types we understand
             "Accept: " (or url-mime-accept-string "*/*") "\r\n"
             ;; User agent
             ;; Proxy Authorization
             ;; Authorization
             ;; Cookies
             (when (url-use-cookies url-http-target-url)
                 host real-fname
                 (equal "https" (url-type url-http-target-url)))))
             ;; If-modified-since
             (if (and (not no-cache)
                      (member url-http-method '("GET" nil)))
                 (let ((tm (url-is-cached url-http-target-url)))
                   (if tm
                       (concat "If-modified-since: "
                               (url-get-normalized-date tm) "\r\n"))))
             ;; Whence we came
             (if ref-url (concat
                          "Referer: " ref-url "\r\n"))
             ;; Length of data
             (if url-http-data
                  "Content-length: " (number-to-string
                                      (length url-http-data))
             ;; End request
             ;; Any data
    ;; Bug#23750
    ;;(unless (= (string-bytes request)
    ;;           (length request))
    ;;  (message "   text byte %d vs %d length" (string-bytes request) (length request)))
      ;;(message "===============================")
      ;;(error "Multibyte text in HTTP request: %s" request))
    (url-http-debug "Request is: \n%s" request)

これで、無事 org2blogから投稿できるようになった。


emacs 25.1 で org2blogを使って WordPress に投稿するには」への3件のフィードバック

  1. ピンバック: Publish with Org2Blog and Solution to non-ascii when posting to WordPress – Welcome to Levi's Site

  2. ピンバック: org2blog läuft wieder | AKO3D Blog, personal, tech

  3. ピンバック: 让org2blog支持中文 | 鳕鱼博客


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です