在google上找了一个bugzilla无法传递object对象的解决方案

Bug 1414063 - Cannot update bug with a comment
Status: CLOSED NOTABUG
 
 
Product: Bugzilla
Component: WebService (Show other bugs)
5.0
Unspecified Unspecified
 
unspecified Severity high (vote)
: ---
: ---
Assigned To: PnT DevOps Devs
tools-bugs
 
 
 
 
:  
 
Depends On:  
Blocks:  
  Show dependency tree / graph
 
Reported: 2017-01-17 11:08 EST by Martin Kosek
Modified: 2017-02-16 02:24 EST (History)
5 users (show)
 
See Also:  
Fixed In Version:  
Doc Type: If docs needed, set a value
Doc Text:  
Clone Of:  
Environment:  
Last Closed: 2017-02-15 18:50:16 EST
 


Attachments(Terms of Use)
Reproducer (751 bytes, text/plain) 
2017-02-15 10:34 ESTMartin Kosek
no flags Details
 
DescriptionMartin Kosek 2017-01-17 11:08:48 EST
Description of problem:

I cannot update Bugzilla with a comment entered:

$ python
...
>>> r = s.put('https://beta.bugzilla.redhat.com/bugzilla/rest/bug/1285012', data={'cf_devel_whiteboard': u'test2', 'comment':{u'body': u'test comment2', 'is_private': False}, 'Bugzilla_token':u'xxxxxxxxx'})
>>> print r.json()
{u'code': 100500, u'message': u'Not a HASH reference at /var/www/html/bugzilla/Bugzilla/WebService/Bug.pm line 746.\n', u'documentation': u'https://beta.bugzilla.redhat.com/bugzilla/docs/en/html/api/index.html', u'error': True}

When I do not have comment hash there, update works:
>>> r = s.put('https://beta.bugzilla.redhat.com/bugzilla/rest/bug/1285012', data={'cf_devel_whiteboard': u'test2', 'Bugzilla_token':u'xxxxxxxxx'})
>>> print r.json()
{u'bugs': [{u'alias': [], u'changes': {u'cf_devel_whiteboard': {u'removed': u'', u'added': u'test2'}}, u'id': 1285012, u'last_change_time': u'2017-01-17T16:00:39Z'}]}

This is the documentation I used:
https://beta.bugzilla.redhat.com/bugzilla/docs/en/html/api/core/v1/bug.html#update-bug

Version-Release number of selected component (if applicable):
5.0.3.rh18

How reproducible:
Always

Steps to Reproduce:
1. Run example Python above
2.
3.

Actual results:
Command always fails

Expected results:
Update with a comment succeeds!

Additional info:
Comment 1Martin Kosek 2017-01-17 17:18:28 EST
BTW, I think there is some systematic error either on my or Bugzilla side, I receive similar error with Flag update:

>>> r = s.put('https://beta.bugzilla.redhat.com/bugzilla/rest/bug/1346342', data={'flags': [{'status': '+', 'name': 'devel_ack'}], 'Bugzilla_token': u'xxxxxxxxxx'})
>>> print r.json()
{u'code': 100500, u'message': u'Can\'t use string ("status") as a HASH ref while "strict refs" in use at /var/www/html/bugzilla/Bugzilla/WebService/Util.pm line 49.\n', u'documentation': u'https://beta.bugzilla.redhat.com/bugzilla/docs/en/html/api/index.html', u'error': True}
Comment 3Jeff Fearn 2017-02-07 20:35:38 EST
I can't duplicate this using perl, if the issue is still occurring please provide a complete example for testing. 

https://beta-bugzilla.redhat.com/show_bug.cgi?id=1285012#c12
https://beta-bugzilla.redhat.com/show_bug.cgi?id=1285012#c13
https://beta-bugzilla.redhat.com/show_bug.cgi?id=1285012#c14
Comment 5Martin Kosek 2017-02-15 10:34 EST
Created attachment 1250634 [details]
Reproducer

Let me attach full Python example that can be used for testing.
Comment 6Jeff Fearn 2017-02-15 18:50:16 EST
You need to s/data/json/ in your script.

Also, API_KEYs really do make scripting easier :)

$ cat rest-test.py
#!/usr/bin/python2

import sys

APIKEY='SECRET'

import requests
s = requests.Session()

r = s.put('https://beta-bugzilla.redhat.com/rest/bug/1346342', json={'comment':{u'body': u'test comment', 'is_private': False}, 'Bugzilla_api_key': APIKEY})

print "Result code:", r.status_code
print "Result text", r.text


$ ./rest-test.py
Result code: 200
Result text {"bugs":[{"changes":{},"id":1346342,"last_change_time":"2017-02-15T23:44:03Z","alias":[]}]}
Comment 7Martin Kosek 2017-02-16 02:24:01 EST
Thanks Jeff! Your advise worked! Now back to porting our tool to the new (nice) Bugzilla REST API.
 

NoteYou need to log in before you can comment on or make changes to this bug.

posted on 2018-02-07 15:42  feifeiyuan  阅读(258)  评论(0编辑  收藏  举报