def _prepareRequest(self, request): # type: (FacebookRequest) -> Dict url = BASE_GRAPH_URL + request.url # type: str data = None # type: Optional[Union[Optional[Dict], Text]] if request.contain_files(): if request.post_params: # Content-Type form-data will be provided by requests lib data = request.post_params else: request.add_headers([ { 'Content-Type': 'application/x-www-form-urlencoded' }, ]) if request.post_params: data = urlencode(convert_params_to_utf8(request.post_params)) return dict( url=url, method=request.method, params=request.params, data=data, headers=request.headers, files=request.files_to_upload(), timeout=request.timeout or self.timeout, )
def url_encode_body(self): """ Convert the post params to a urlencoded str :rtype: str """ params = self.post_params if not params: return None return urlencode(convert_params_to_utf8(params))
def batch_url(self): """ The relative url to the graph api. :rtype: str """ params = self.params url = self.url if self.method != METHOD_POST and params: return '{url}?{encoded_params}'.format( url=url, encoded_params=urlencode(convert_params_to_utf8(self.params))) return url