mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-13 16:40:50 -07:00
Fix urlopen usage to use open_url instead
Add a travis test for urlopen usage
This commit is contained in:
parent
e97d448838
commit
3db8070aa3
9 changed files with 52 additions and 54 deletions
|
@ -16,7 +16,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import urllib
|
||||
import urllib2
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
|
@ -27,6 +26,7 @@ from optparse import OptionParser
|
|||
|
||||
from six import iteritems
|
||||
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
class ProxmoxNodeList(list):
|
||||
def get_names(self):
|
||||
|
@ -86,7 +86,7 @@ class ProxmoxAPI(object):
|
|||
'password': self.options.password,
|
||||
})
|
||||
|
||||
data = json.load(urllib2.urlopen(request_path, request_params))
|
||||
data = json.load(open_url(request_path, data=request_params))
|
||||
|
||||
self.credentials = {
|
||||
'ticket': data['data']['ticket'],
|
||||
|
@ -94,11 +94,10 @@ class ProxmoxAPI(object):
|
|||
}
|
||||
|
||||
def get(self, url, data=None):
|
||||
opener = urllib2.build_opener()
|
||||
opener.addheaders.append(('Cookie', 'PVEAuthCookie={}'.format(self.credentials['ticket'])))
|
||||
|
||||
request_path = '{}{}'.format(self.options.url, url)
|
||||
request = opener.open(request_path, data)
|
||||
|
||||
headers = {'Cookie': 'PVEAuthCookie={}'.format(self.credentials['ticket'])}
|
||||
request = open_url(request_path, data=data, headers=headers)
|
||||
|
||||
response = json.load(request)
|
||||
return response['data']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue