方法把python擅离401

时间:2013-07-05 12:50:26

标签: python put unauthorized

我有一个python脚本,我会将图像发送到服务器,所以我使用“put”方法, 服务器响应:401未经授权

======================================================================
FAIL: test_EnvoiPhotos (__main__.EnvoiPhotos)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "build/bdist.linux-i686/egg/funkload/FunkLoadTestCase.py", line 946, in __call__
    testMethod()
  File "test_EnvoiPhotos.py", line 74, in test_EnvoiPhotos
    self.put(self.server_url + "/contacts/41.json",Data('application/json',data),description = "put photo")
  File "build/bdist.linux-i686/egg/funkload/FunkLoadTestCase.py", line 408, in put
    load_auto_links=load_auto_links)
  File "build/bdist.linux-i686/egg/funkload/FunkLoadTestCase.py", line 401, in method
    method=method, load_auto_links=load_auto_links)
  File "build/bdist.linux-i686/egg/funkload/FunkLoadTestCase.py", line 299, in _browse
    response = self._connect(url, params, ok_codes, method, description)
  File "build/bdist.linux-i686/egg/funkload/FunkLoadTestCase.py", line 216, in _connect
    raise self.failureException, str(value.response)
AssertionError: /contacts/41.json
HTTP Response 401: Unauthorized

我使用funkload来测试我的应用程序网站

这是我的代码的一部分:

#generation nombre between 1 et 109
i = random.randint(1,109)
#read photo
nameimage = "im"
nameimage=nameimage+str(i).zfill(1)+'.jpg'
self.logd(nameimage)
filephoto=open(nameimage,'rb')
image_data=filephoto.read()
filephoto.close()


b64_text = base64.b64encode(image_data)


const_image = {}
const_image['id'] = i
const_image['first_name'] = 'guest'
const_image['last_name'] = 'guest'
const_image['playload'] = b64_text
data=json.dumps(const_image)

#self.logd(data)

self.setHeader('content-type', 'application/json')

#next request


self.put(self.server_url+"/contacts/41.json",Data('application/json',data),description = "put photo")

0 个答案:

没有答案