That's it. Thank you David.

On Friday, 7 July 2017 07:52:59 UTC+2, David Trowbridge wrote:
>
> You're very close. This one is the correct version:
>
> r = requests.post(rbpath, data=rbrepo, auth=HTTPBasicAuth('admin', 
> 'xxxx'))
>
> But then there's a problem in your "rbrepo" structure. The "tool" field 
> has a space after it within the string. If you get rid of that space, 
> everything should work as expected.
>
> -David
>
> On Thu, Jul 6, 2017 at 10:41 PM Morten Laursen <[email protected] 
> <javascript:>> wrote:
>
>> Reason for this format is 
>> https://www.reviewboard.org/docs/manual/1.5/webapi/2.0/overview/#making-requests
>> :
>> "The supplied content must be represented as multi-part form data."
>>
>> With 
>>         r = requests.post(rbpath, data=rbrepo, 
>> auth=HTTPBasicAuth('admin', 'xxxx'))
>> it also fails:
>>
>> POST /api/repositories/ HTTP/1.1
>>
>> Host: reviewboard.rtx.loc
>>
>> User-Agent: python-requests/2.18.1
>>
>> Accept-Encoding: gzip, deflate
>>
>> Accept: */*
>>
>> Connection: keep-alive
>>
>> Content-Length: 128
>>
>> Content-Type: application/x-www-form-urlencoded
>>
>> Authorization: Basic YWRtaW46cmI5MzAz
>>
>>
>> name=Components%2Frptest%2FComp1&tool+=Mercurial&path=https%3A%2F%
>> 2Frepo.rtx.net%2Fhg%2FComponents%2Frptest%2FComp1&trust_host=1HTTP/1.1 
>> 400 BAD REQUEST
>>
>> Date: Fri, 07 Jul 2017 05:34:53 GMT
>>
>> Server: Apache/2.4.18 (Ubuntu)
>>
>> Content-Length: 163
>>
>> Content-Language: en
>>
>> X-Content-Type-Options: nosniff
>>
>> Expires: Fri, 07 Jul 2017 05:34:53 GMT
>>
>> Vary: Accept,Cookie,Accept-Language
>>
>> Last-Modified: Fri, 07 Jul 2017 05:34:53 GMT
>>
>> Cache-Control: max-age=0
>>
>> X-Frame-Options: SAMEORIGIN
>>
>> Set-Cookie: rbsessionid=kw48gf216ykzg48y6b8cvxwvg4ekzjca; expires=Sat, 
>> 07-Jul-2018 05:34:53 GMT; httponly; Max-Age=31536000; Path=/
>>
>> Connection: close
>>
>> Content-Type: application/vnd.reviewboard.org.error+json
>>
>>
>> {"fields": {"tool": ["This field is required"], "tool ": ["Field is not 
>> supported"]}, "stat": "fail", "err": {"msg": "One or more fields had 
>> errors", "code": 105}}
>>
>> Also tried 
>>        r = requests.post(rbpath, json=rbrepo, 
>> auth=HTTPBasicAuth('admin', 'xxxx'))
>>
>> POST /api/repositories/ HTTP/1.1
>>
>> Host: reviewboard.rtx.loc
>>
>> User-Agent: python-requests/2.18.1
>>
>> Accept-Encoding: gzip, deflate
>>
>> Accept: */*
>>
>> Connection: keep-alive
>>
>> Content-Length: 135
>>
>> Content-Type: application/json
>>
>> Authorization: Basic YWRtaW46cmI5MzAz
>>
>>
>> {"name": "Components/rptest/Comp1", "tool ": "Mercurial", "path": "
>> https://repo.rtx.net/hg/Components/rptest/Comp1";, "trust_host": "1"}HTTP/1.1 
>> 400 BAD REQUEST
>>
>> Date: Fri, 07 Jul 2017 05:36:43 GMT
>>
>> Server: Apache/2.4.18 (Ubuntu)
>>
>> Content-Length: 198
>>
>> Content-Language: en
>>
>> X-Content-Type-Options: nosniff
>>
>> Expires: Fri, 07 Jul 2017 05:36:43 GMT
>>
>> Vary: Accept,Cookie,Accept-Language
>>
>> Last-Modified: Fri, 07 Jul 2017 05:36:43 GMT
>>
>> Cache-Control: max-age=0
>>
>> X-Frame-Options: SAMEORIGIN
>>
>> Set-Cookie: rbsessionid=e6vhlti911jb4m1hqsdr37ia3hv3e4y9; expires=Sat, 
>> 07-Jul-2018 05:36:43 GMT; httponly; Max-Age=31536000; Path=/
>>
>> Connection: close
>>
>> Content-Type: application/vnd.reviewboard.org.error+json
>>
>>
>> {"fields": {"path": ["This field is required"], "tool": ["This field is 
>> required"], "name": ["This field is required"]}, "stat": "fail", "err": 
>> {"msg": "One or more fields had errors", "code": 105}}
>>
>> On Thursday, 6 July 2017 18:11:18 UTC+2, David Trowbridge wrote:
>>
>>> Morten,
>>>
>>> It looks like it's probably failing because your payload is being passed 
>>> in as files (which is used for uploading diffs or attachments but not for 
>>> the vast majority of API fields). If you do data=rbrepo it should work.
>>>
>>> -David
>>>
>> On Thu, Jul 6, 2017 at 8:52 AM Morten Laursen <[email protected]> wrote:
>>>
>> Hi
>>>>
>>>> I am trying to add repositories using the REST API and Python:
>>>>
>>>>         rbpath = 'http://reviewboard.rtx.loc/api/repositories/'
>>>>         scmmgrpath = 'https://repo.rtx.net/hg/'
>>>>         rbrepo = { 
>>>>             'name' : str(repo),
>>>>             'tool ': 'Mercurial',
>>>>             'path' : scmmgrpath + str(repo),
>>>>             }
>>>>         r = requests.post(rbpath, files=rbrepo, 
>>>> auth=HTTPBasicAuth('admin', 'xxxx'))
>>>>
>>>> Resulting HTTP requests and response:
>>>>
>>>> POST /api/repositories/ HTTP/1.1
>>>>
>>>> Host: reviewboard.rtx.loc
>>>>
>>>> User-Agent: python-requests/2.18.1
>>>>
>>>> Accept-Encoding: gzip, deflate
>>>>
>>>> Accept: */*
>>>>
>>>> Connection: keep-alive
>>>>
>>>> Content-Length: 540
>>>>
>>>> Content-Type: multipart/form-data; 
>>>> boundary=29fd7488bc224bffa7f6f10a2d224478
>>>>
>>>> Authorization: Basic YWRtaW46cmI5MzAz
>>>>
>>>>
>>>> --29fd7488bc224bffa7f6f10a2d224478
>>>>
>>>> Content-Disposition: form-data; name="name"; filename="name"
>>>>
>>>>
>>>> Components/rptest/Comp1
>>>>
>>>> --29fd7488bc224bffa7f6f10a2d224478
>>>>
>>>> Content-Disposition: form-data; name="tool "; filename="tool "
>>>>
>>>>
>>>> Mercurial
>>>>
>>>> --29fd7488bc224bffa7f6f10a2d224478
>>>>
>>>> Content-Disposition: form-data; name="path"; filename="path"
>>>>
>>>>
>>>> --29fd7488bc224bffa7f6f10a2d224478--
>>>>
>>>> HTTP/1.1 400 BAD REQUEST
>>>>
>>>> Date: Thu, 06 Jul 2017 11:51:50 GMT
>>>>
>>>> Server: Apache/2.4.18 (Ubuntu)
>>>>
>>>> Content-Length: 198
>>>>
>>>> Content-Language: en
>>>>
>>>> X-Content-Type-Options: nosniff
>>>>
>>>> Expires: Thu, 06 Jul 2017 11:51:50 GMT
>>>>
>>>> Vary: Accept,Cookie,Accept-Language
>>>>
>>>> Last-Modified: Thu, 06 Jul 2017 11:51:50 GMT
>>>>
>>>> Cache-Control: max-age=0
>>>>
>>>> X-Frame-Options: SAMEORIGIN
>>>>
>>>> Set-Cookie: rbsessionid=0260ffin91cnxo5yq5kweiiyfji3r34g; expires=Fri, 
>>>> 06-Jul-2018 11:51:50 GMT; httponly; Max-Age=31536000; Path=/
>>>>
>>>> Connection: close
>>>>
>>>> Content-Type: text/plain
>>>>
>>>>
>>>> {"fields": {"path": ["This field is required"], "tool": ["This field is 
>>>> required"], "name": ["This field is required"]}, "stat": "fail", "err": 
>>>> {"msg": "One or more fields had errors", "code": 105}}
>>>>
>>>>
>>>> Any idea why this is failing?
>>>> I think the encoding looks quite much like rbt's requests (biggest 
>>>> difference is the "filename=.." part, not quite sure how to get rid of 
>>>> that 
>>>> using requests libarary).
>>>>
>>>> Or are there simpler ways to remotely configure repos?
>>>>
>>>> Thanks,
>>>> Morten
>>>>
>>>> -- 
>>>> Supercharge your Review Board with Power Pack: 
>>>> https://www.reviewboard.org/powerpack/
>>>> Want us to host Review Board for you? Check out RBCommons: 
>>>> https://rbcommons.com/
>>>> Happy user? Let us know! https://www.reviewboard.org/users/
>>>> --- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "reviewboard" group.
>>>>
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>
>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> Supercharge your Review Board with Power Pack: 
>> https://www.reviewboard.org/powerpack/
>> Want us to host Review Board for you? Check out RBCommons: 
>> https://rbcommons.com/
>> Happy user? Let us know! https://www.reviewboard.org/users/
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "reviewboard" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Supercharge your Review Board with Power Pack: 
https://www.reviewboard.org/powerpack/
Want us to host Review Board for you? Check out RBCommons: 
https://rbcommons.com/
Happy user? Let us know! https://www.reviewboard.org/users/
--- 
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to