Skip to content

Commit 91d3f41

Browse files
committed
Something confusing about PUT request
It's solved as a provisional patch
1 parent 29d7c56 commit 91d3f41

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pygithub3/core/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,9 @@ def patch(self, request, **kwargs):
9595
return response
9696

9797
def put(self, request, **kwargs):
98-
# TODO: Search info about this (bug in requests? in api? me?)
99-
incoming_headers = kwargs.get('headers', {})
100-
incoming_headers.update({'Content-length': '0'})
101-
kwargs['headers'] = incoming_headers
10298
response = self.request('put', request, **kwargs)
103-
assert response.status_code != '204'
99+
# assert response.status_code != '204'
100+
# I don't do an assert. See `services.base.Base._put` comment
104101
return response
105102

106103
def delete(self, request, **kwargs):

pygithub3/services/base.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,27 @@ def _patch(self, request_uri, **kwargs):
4545

4646
def _put(self, request_uri, **kwargs):
4747
request = self.get_request(request_uri)
48-
self.client.put(request, **kwargs)
48+
resource = request.get_resource()
49+
""" Bug in Github API? requests library?
50+
51+
I must send data as empty string when the specifications' of some PUT
52+
request are 'Not send input data'. If I don't do that and send data as
53+
None, the requests library doesn't send 'Content-length' header and the
54+
server returns 411 - Required Content length (at least 0)
55+
56+
For instance:
57+
- follow-user request doesn't send input data
58+
- merge-pull request send data
59+
60+
For that reason I must do a conditional because I don't want to return
61+
an empty string on follow-user request because it could be confused
62+
63+
Related: ht
64+
"""
65+
input_data = request.get_data() or ''
66+
response = self.client.put(request, data=input_data, **kwargs)
67+
if response.status_code != '204': # != NO_CONTENT
68+
return resource.loads(response.content)
4969

5070
def _delete(self, request_uri, **kwargs):
5171
request = self.get_request(request_uri)

0 commit comments

Comments
 (0)