{"action":"created","comment":{"url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/comments/58140975","id":58140975,"diff_hunk":"@@ -0,0 +1,178 @@\n+######################################################################\n+#\n+# File: b2/b2http.py\n+#\n+# Copyright 2016 Backblaze Inc. All Rights Reserved.\n+#\n+# License https://www.backblaze.com/using_b2_code.html\n+#\n+######################################################################\n+\n+from __future__ import print_function\n+\n+import json\n+import requests\n+import six\n+import socket\n+\n+\n+class WebApiError(Exception):\n+    \"\"\"\n+    Holds information extracted from a call to a B2 API.\n+\n+    When an error happens, B2 returns an error JSON that looks like this:\n+\n+        {\n+            \"status\" : 400,\n+            \"code\" : \"invalid_bucket_name\",\n+            \"message\" : \"bucket name is too long\"\n+        }\n+    \"\"\"\n+\n+    def __init__(self, status, code, message):\n+        super(WebApiError, self).__init__(status, code, message)\n+        self.status = status\n+        self.code = code\n+        self.message = message\n+\n+    def __repr__(self):\n+        return \"WebApiError(%d, '%s', '%s')\" % (self.status, self.code, self.message)\n+\n+    def __eq__(self, other):\n+        return repr(self) == repr(other)\n+\n+    def __ne__(self, other):\n+        return not self.__eq__(other)\n+\n+\n+def _print_exception(e, indent=''):\n+    \"\"\"\n+    Used for debugging to print out nested exception structures.\n+    \"\"\"\n+    print(indent + 'EXCEPTION', repr(e))\n+    print(indent + 'CLASS', type(e))\n+    for (i, a) in enumerate(e.args):\n+        print(indent + 'ARG %d: %s' % (i, repr(a)))\n+        if isinstance(a, Exception):\n+            _print_exception(a, indent + '        ')\n+\n+\n+def _translate_errors(fcn):\n+    \"\"\"\n+    Calls the given function, turning any exception raised into a WebApiError.\n+    \"\"\"\n+    try:\n+        response = fcn()\n+        if response.status_code not in [200, 206]:\n+            # Decode the error object returned by the service\n+            error = json.loads(response.content.decode('utf-8'))\n+            raise WebApiError(int(error['status']), error['code'], error['message'])\n+        return response\n+\n+    except WebApiError:\n+        raise  # pass through exceptions from just above\n+\n+    except requests.ConnectionError as e0:\n+        e1 = e0.args[0]\n+        if isinstance(e1, requests.packages.urllib3.exceptions.MaxRetryError):\n+            msg = e1.args[0]\n+            if 'nodename nor servname provided, or not known' in msg:\n+                # Unknown host, or DNS failing.  In the context of calling\n+                # B2, this means that something is down between here and\n+                # Backblaze, so we treat it like 503 Service Unavailable.\n+                raise WebApiError(503, 'unknown_host', 'unable to locate host')\n+        elif isinstance(e1, requests.packages.urllib3.exceptions.ProtocolError):\n+            e2 = e1.args[1]\n+            if isinstance(e2, socket.error):\n+                if e2.args[1] == 'Broken pipe':\n+                    # Broken pipes are usually caused by the service rejecting\n+                    # an upload request for cause, so we use a 400 Bad Request","path":"b2/b2http.py","position":89,"original_position":89,"commit_id":"6900d3614a6b338037f43d9dfa10e7649681e126","original_commit_id":"6900d3614a6b338037f43d9dfa10e7649681e126","user":{"login":"ppolewicz","id":726553,"avatar_url":"https://avatars.githubusercontent.com/u/726553?v=3","gravatar_id":"","url":"https://api.github.com/users/ppolewicz","html_url":"https://github.com/ppolewicz","followers_url":"https://api.github.com/users/ppolewicz/followers","following_url":"https://api.github.com/users/ppolewicz/following{/other_user}","gists_url":"https://api.github.com/users/ppolewicz/gists{/gist_id}","starred_url":"https://api.github.com/users/ppolewicz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppolewicz/subscriptions","organizations_url":"https://api.github.com/users/ppolewicz/orgs","repos_url":"https://api.github.com/users/ppolewicz/repos","events_url":"https://api.github.com/users/ppolewicz/events{/privacy}","received_events_url":"https://api.github.com/users/ppolewicz/received_events","type":"User","site_admin":false},"body":"Comment inconsistent with the code","created_at":"2016-03-31T22:53:25Z","updated_at":"2016-03-31T22:53:25Z","html_url":"https://github.com/Backblaze/B2_Command_Line_Tool/pull/103#discussion_r58140975","pull_request_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103","_links":{"self":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/comments/58140975"},"html":{"href":"https://github.com/Backblaze/B2_Command_Line_Tool/pull/103#discussion_r58140975"},"pull_request":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103"}}},"pull_request":{"url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103","id":64818804,"html_url":"https://github.com/Backblaze/B2_Command_Line_Tool/pull/103","diff_url":"https://github.com/Backblaze/B2_Command_Line_Tool/pull/103.diff","patch_url":"https://github.com/Backblaze/B2_Command_Line_Tool/pull/103.patch","issue_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/103","number":103,"state":"open","locked":false,"title":"Tiny wrapper for requests","user":{"login":"bwbeach","id":603739,"avatar_url":"https://avatars.githubusercontent.com/u/603739?v=3","gravatar_id":"","url":"https://api.github.com/users/bwbeach","html_url":"https://github.com/bwbeach","followers_url":"https://api.github.com/users/bwbeach/followers","following_url":"https://api.github.com/users/bwbeach/following{/other_user}","gists_url":"https://api.github.com/users/bwbeach/gists{/gist_id}","starred_url":"https://api.github.com/users/bwbeach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwbeach/subscriptions","organizations_url":"https://api.github.com/users/bwbeach/orgs","repos_url":"https://api.github.com/users/bwbeach/repos","events_url":"https://api.github.com/users/bwbeach/events{/privacy}","received_events_url":"https://api.github.com/users/bwbeach/received_events","type":"User","site_admin":false},"body":"Not ready to merge yet, but would like comments.\r\n\r\n","created_at":"2016-03-31T16:24:41Z","updated_at":"2016-03-31T22:53:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f7b37ffecf506491cde2b368191ba2a14eab359","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103/commits","review_comments_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103/comments","review_comment_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/103/comments","statuses_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/statuses/6900d3614a6b338037f43d9dfa10e7649681e126","head":{"label":"Backblaze:requests","ref":"requests","sha":"6900d3614a6b338037f43d9dfa10e7649681e126","user":{"login":"Backblaze","id":10283486,"avatar_url":"https://avatars.githubusercontent.com/u/10283486?v=3","gravatar_id":"","url":"https://api.github.com/users/Backblaze","html_url":"https://github.com/Backblaze","followers_url":"https://api.github.com/users/Backblaze/followers","following_url":"https://api.github.com/users/Backblaze/following{/other_user}","gists_url":"https://api.github.com/users/Backblaze/gists{/gist_id}","starred_url":"https://api.github.com/users/Backblaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Backblaze/subscriptions","organizations_url":"https://api.github.com/users/Backblaze/orgs","repos_url":"https://api.github.com/users/Backblaze/repos","events_url":"https://api.github.com/users/Backblaze/events{/privacy}","received_events_url":"https://api.github.com/users/Backblaze/received_events","type":"Organization","site_admin":false},"repo":{"id":46293472,"name":"B2_Command_Line_Tool","full_name":"Backblaze/B2_Command_Line_Tool","owner":{"login":"Backblaze","id":10283486,"avatar_url":"https://avatars.githubusercontent.com/u/10283486?v=3","gravatar_id":"","url":"https://api.github.com/users/Backblaze","html_url":"https://github.com/Backblaze","followers_url":"https://api.github.com/users/Backblaze/followers","following_url":"https://api.github.com/users/Backblaze/following{/other_user}","gists_url":"https://api.github.com/users/Backblaze/gists{/gist_id}","starred_url":"https://api.github.com/users/Backblaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Backblaze/subscriptions","organizations_url":"https://api.github.com/users/Backblaze/orgs","repos_url":"https://api.github.com/users/Backblaze/repos","events_url":"https://api.github.com/users/Backblaze/events{/privacy}","received_events_url":"https://api.github.com/users/Backblaze/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Backblaze/B2_Command_Line_Tool","description":"The command-line tool that gives easy access to all of the capabilities of B2 Cloud Storage","fork":false,"url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool","forks_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/forks","keys_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/teams","hooks_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/hooks","issue_events_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/events{/number}","events_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/events","assignees_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/assignees{/user}","branches_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/branches{/branch}","tags_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/tags","blobs_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/refs{/sha}","trees_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/statuses/{sha}","languages_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/languages","stargazers_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/stargazers","contributors_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/contributors","subscribers_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/subscribers","subscription_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/subscription","commits_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/commits{/sha}","git_commits_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/commits{/sha}","comments_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/comments{/number}","issue_comment_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/comments{/number}","contents_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/contents/{+path}","compare_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/merges","archive_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/downloads","issues_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues{/number}","pulls_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls{/number}","milestones_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/milestones{/number}","notifications_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/labels{/name}","releases_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/releases{/id}","deployments_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/deployments","created_at":"2015-11-16T18:22:50Z","updated_at":"2016-03-31T08:15:47Z","pushed_at":"2016-03-31T22:23:25Z","git_url":"git://github.com/Backblaze/B2_Command_Line_Tool.git","ssh_url":"git@github.com:Backblaze/B2_Command_Line_Tool.git","clone_url":"https://github.com/Backblaze/B2_Command_Line_Tool.git","svn_url":"https://github.com/Backblaze/B2_Command_Line_Tool","homepage":null,"size":416,"stargazers_count":96,"watchers_count":96,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":15,"forks":16,"open_issues":15,"watchers":96,"default_branch":"master"}},"base":{"label":"Backblaze:master","ref":"master","sha":"19517fd4d89b10639969076da91e8c7d3a5c2691","user":{"login":"Backblaze","id":10283486,"avatar_url":"https://avatars.githubusercontent.com/u/10283486?v=3","gravatar_id":"","url":"https://api.github.com/users/Backblaze","html_url":"https://github.com/Backblaze","followers_url":"https://api.github.com/users/Backblaze/followers","following_url":"https://api.github.com/users/Backblaze/following{/other_user}","gists_url":"https://api.github.com/users/Backblaze/gists{/gist_id}","starred_url":"https://api.github.com/users/Backblaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Backblaze/subscriptions","organizations_url":"https://api.github.com/users/Backblaze/orgs","repos_url":"https://api.github.com/users/Backblaze/repos","events_url":"https://api.github.com/users/Backblaze/events{/privacy}","received_events_url":"https://api.github.com/users/Backblaze/received_events","type":"Organization","site_admin":false},"repo":{"id":46293472,"name":"B2_Command_Line_Tool","full_name":"Backblaze/B2_Command_Line_Tool","owner":{"login":"Backblaze","id":10283486,"avatar_url":"https://avatars.githubusercontent.com/u/10283486?v=3","gravatar_id":"","url":"https://api.github.com/users/Backblaze","html_url":"https://github.com/Backblaze","followers_url":"https://api.github.com/users/Backblaze/followers","following_url":"https://api.github.com/users/Backblaze/following{/other_user}","gists_url":"https://api.github.com/users/Backblaze/gists{/gist_id}","starred_url":"https://api.github.com/users/Backblaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Backblaze/subscriptions","organizations_url":"https://api.github.com/users/Backblaze/orgs","repos_url":"https://api.github.com/users/Backblaze/repos","events_url":"https://api.github.com/users/Backblaze/events{/privacy}","received_events_url":"https://api.github.com/users/Backblaze/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Backblaze/B2_Command_Line_Tool","description":"The command-line tool that gives easy access to all of the capabilities of B2 Cloud Storage","fork":false,"url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool","forks_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/forks","keys_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/teams","hooks_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/hooks","issue_events_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/events{/number}","events_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/events","assignees_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/assignees{/user}","branches_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/branches{/branch}","tags_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/tags","blobs_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/refs{/sha}","trees_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/statuses/{sha}","languages_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/languages","stargazers_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/stargazers","contributors_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/contributors","subscribers_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/subscribers","subscription_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/subscription","commits_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/commits{/sha}","git_commits_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/git/commits{/sha}","comments_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/comments{/number}","issue_comment_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/comments{/number}","contents_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/contents/{+path}","compare_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/merges","archive_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/downloads","issues_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues{/number}","pulls_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls{/number}","milestones_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/milestones{/number}","notifications_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/labels{/name}","releases_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/releases{/id}","deployments_url":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/deployments","created_at":"2015-11-16T18:22:50Z","updated_at":"2016-03-31T08:15:47Z","pushed_at":"2016-03-31T22:23:25Z","git_url":"git://github.com/Backblaze/B2_Command_Line_Tool.git","ssh_url":"git@github.com:Backblaze/B2_Command_Line_Tool.git","clone_url":"https://github.com/Backblaze/B2_Command_Line_Tool.git","svn_url":"https://github.com/Backblaze/B2_Command_Line_Tool","homepage":null,"size":416,"stargazers_count":96,"watchers_count":96,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":15,"forks":16,"open_issues":15,"watchers":96,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103"},"html":{"href":"https://github.com/Backblaze/B2_Command_Line_Tool/pull/103"},"issue":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/103"},"comments":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/issues/103/comments"},"review_comments":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103/comments"},"review_comment":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/pulls/103/commits"},"statuses":{"href":"https://api.github.com/repos/Backblaze/B2_Command_Line_Tool/statuses/6900d3614a6b338037f43d9dfa10e7649681e126"}}}}