10
10
import logging
11
11
from json import dumps as jsonencode
12
12
13
- from six import binary_type , text_type
14
- from wordpress .auth import BasicAuth , OAuth , OAuth_3Leg , NoAuth
13
+ from six import text_type
14
+ from wordpress .auth import BasicAuth , NoAuth , OAuth , OAuth_3Leg
15
15
from wordpress .helpers import StrUtils , UrlUtils
16
16
from wordpress .transport import API_Requests_Wrapper
17
17
@@ -38,7 +38,10 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs):
38
38
elif kwargs .get ('no_auth' ):
39
39
auth_class = NoAuth
40
40
41
- if kwargs .get ('version' , '' ).startswith ('wc' ) and kwargs .get ('oauth1a_3leg' ):
41
+ if (
42
+ kwargs .get ('version' , '' ).startswith ('wc' )
43
+ and kwargs .get ('oauth1a_3leg' )
44
+ ):
42
45
self .logger .warn (
43
46
"WooCommerce JSON Api does not seem to support 3leg" )
44
47
@@ -106,9 +109,13 @@ def request_post_mortem(self, response=None):
106
109
107
110
try_hostname_mismatch = False
108
111
109
- if isinstance (response_json , dict ) and ('code' in response_json or 'message' in response_json ):
112
+ if (
113
+ isinstance (response_json , dict )
114
+ and ('code' in response_json or 'message' in response_json )
115
+ ):
110
116
reason = u" - " .join ([
111
- text_type (response_json .get (key )) for key in ['code' , 'message' , 'data' ]
117
+ text_type (response_json .get (key ))
118
+ for key in ['code' , 'message' , 'data' ]
112
119
if key in response_json
113
120
])
114
121
code = text_type (response_json .get ('code' ))
@@ -126,16 +133,19 @@ def request_post_mortem(self, response=None):
126
133
remedy = "Try enabling query_string_auth"
127
134
else :
128
135
remedy = (
129
- "This error is super generic and can be caused by just "
130
- "about anything. Here are some things to try: \n "
136
+ "This error is super generic and can be caused by "
137
+ "just about anything. Here are some things to try: \n "
131
138
" - Check that the account which as assigned to your "
132
139
"oAuth creds has the correct access level\n "
133
140
" - Enable logging and check for error messages in "
134
141
"wp-content and wp-content/uploads/wc-logs\n "
135
- " - Check that your query string parameters are valid\n "
136
- " - Make sure your server is not messing with authentication headers\n "
142
+ " - Check that your query string parameters are "
143
+ "valid\n "
144
+ " - Make sure your server is not messing with "
145
+ "authentication headers\n "
137
146
" - Try a different endpoint\n "
138
- " - Try enabling HTTPS and using basic authentication\n "
147
+ " - Try enabling HTTPS and using basic "
148
+ "authentication\n "
139
149
)
140
150
141
151
elif code == 'woocommerce_rest_authentication_error' :
@@ -169,7 +179,10 @@ def request_post_mortem(self, response=None):
169
179
header_url = StrUtils .eviscerate (header_url , '/' )
170
180
remedy = "try changing url to %s" % header_url
171
181
172
- msg = u"API call to %s returned \n CODE: %s\n RESPONSE:%s \n HEADERS: %s\n REQ_BODY:%s" % (
182
+ msg = (
183
+ u"API call to %s returned \n CODE: "
184
+ "%s\n RESPONSE:%s \n HEADERS: %s\n REQ_BODY:%s"
185
+ ) % (
173
186
request_url ,
174
187
text_type (response .status_code ),
175
188
UrlUtils .beautify_response (response ),
0 commit comments