|
7 | 7 | import base64 |
8 | 8 | import datetime |
9 | 9 | import re |
| 10 | +import requests |
10 | 11 | import six |
11 | 12 |
|
12 | | -from six.moves.urllib.request import Request, urlopen |
13 | 13 | from six.moves.urllib.parse import urlencode |
14 | 14 | from xml.dom import pulldom, Node |
15 | 15 |
|
16 | 16 | from django.conf import settings |
17 | | -from django.utils.encoding import smart_bytes, force_str |
| 17 | +from django.utils.encoding import smart_bytes, force_str, force_text |
18 | 18 |
|
19 | 19 | import debug # pyflakes:ignore |
20 | 20 |
|
|
27 | 27 | from ietf.person.models import Person |
28 | 28 | from ietf.utils.log import log |
29 | 29 | from ietf.utils.mail import send_mail_text |
30 | | -from ietf.utils.text import decode |
31 | 30 |
|
32 | 31 | #QUEUE_URL = "https://www.rfc-editor.org/queue2.xml" |
33 | 32 | #INDEX_URL = "https://www.rfc-editor.org/rfc/rfc-index.xml" |
@@ -530,28 +529,28 @@ def post_approved_draft(url, name): |
530 | 529 | the data from the Datatracker and start processing it. Returns |
531 | 530 | response and error (empty string if no error).""" |
532 | 531 |
|
533 | | - request = Request(url) |
534 | | - request.add_header("Content-type", "application/x-www-form-urlencoded") |
535 | | - request.add_header("Accept", "text/plain") |
536 | 532 | # HTTP basic auth |
537 | 533 | username = "dtracksync" |
538 | 534 | password = settings.RFC_EDITOR_SYNC_PASSWORD |
539 | | - request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", "")) |
| 535 | + headers = { |
| 536 | + "Content-type": "application/x-www-form-urlencoded", |
| 537 | + "Accept": "text/plain", |
| 538 | + "Authorization": "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""), |
| 539 | + } |
540 | 540 |
|
541 | 541 | log("Posting RFC-Editor notifcation of approved draft '%s' to '%s'" % (name, url)) |
542 | 542 | text = error = "" |
| 543 | + |
543 | 544 | try: |
544 | | - f = urlopen(request, data=smart_bytes(urlencode({ 'draft': name })), timeout=20) |
545 | | - text = decode(f.read()) |
546 | | - status_code = f.getcode() |
547 | | - f.close() |
548 | | - log("RFC-Editor notification result for draft '%s': %s:'%s'" % (name, status_code, text)) |
| 545 | + r = requests.post(url, headers=headers, data=smart_bytes(urlencode({ 'draft': name })), timeout=20) |
| 546 | + |
| 547 | + log("RFC-Editor notification result for draft '%s': %s:'%s'" % (name, r.status_code, r.text)) |
549 | 548 |
|
550 | | - if status_code != 200: |
551 | | - raise RuntimeError("Status code is not 200 OK (it's %s)." % status_code) |
| 549 | + if r.status_code != 200: |
| 550 | + raise RuntimeError("Status code is not 200 OK (it's %s)." % r.status_code) |
552 | 551 |
|
553 | | - if text != "OK": |
554 | | - raise RuntimeError("Response is not \"OK\".") |
| 552 | + if force_text(r.text) != "OK": |
| 553 | + raise RuntimeError('Response is not "OK" (it\'s "%s").' % r.text) |
555 | 554 |
|
556 | 555 | except Exception as e: |
557 | 556 | # catch everything so we don't leak exceptions, convert them |
|
0 commit comments