Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 19 22:35
    prkumar opened #189
  • Jan 19 22:27
    prkumar edited #185
  • Jan 19 22:27
    prkumar commented #185
  • Jan 10 17:35

    prkumar on master

    Exclude tests subpackages from … (compare)

  • Jan 10 17:35
    prkumar closed #188
  • Jan 10 17:32
    prkumar milestoned #188
  • Jan 10 17:32
    prkumar demilestoned #188
  • Jan 10 17:32
    prkumar milestoned #188
  • Jan 10 17:32
    prkumar review_requested #188
  • Jan 10 15:38
    codecov[bot] commented #188
  • Jan 10 15:37
    codecov[bot] commented #188
  • Jan 10 15:37
    codecov[bot] commented #188
  • Jan 10 15:36
    codecov[bot] commented #188
  • Jan 10 15:36
    codecov[bot] commented #188
  • Jan 10 15:35
    daa opened #188
  • Jan 02 16:46

    prkumar on master

    Migrate repo to travis-ci.com (compare)

  • Jan 02 16:46
    prkumar closed #187
  • Jan 02 03:42
    codecov[bot] commented #187
  • Jan 02 03:41
    codecov[bot] commented #187
  • Jan 02 03:41
    codecov[bot] commented #187
Or Carmi
@liiight
I wonder how tricky it'll be though 🤔
Alexandre Collet
@Shanoir
@prkumar Roger that. Right now my workaround is working, so no problemo :)
Or Carmi
@liiight
@prkumar im having major issues sending a multipart request. Seems I keep getting:
    @staticmethod
    def _default_json_dumper(obj):
>       return obj.__dict__  # pragma: no cover
E       AttributeError: 'bytes' object has no attribute '__dict__'
Or Carmi
@liiight
for some reason it want to json dumps the binary file, even though it's annotated as Part with the @multipart decorator used as well
P. Raj Kumar
@prkumar
@liiight Hmmm.... as you noticed, the StandardConverter always tries to do a json dump when the request is not a string. I definitely need to reevaluate this: could you create a GitHub issue for me?
There is a workaround here: you can register your own Converter
Try this (untested) workaround:
from uplink.converters import interfaces, register_default_converter_factory

@register_default_converter_factory
class PassThroughConverter(interfaces.Factory):
    def create_request_body_converter(self, type_, *args, **kwargs):
        return lambda value: value
P. Raj Kumar
@prkumar
^ This just tells uplink to just pass the request body through
Or Carmi
@liiight
I will open a github issue and try the workaround. Thanks
Or Carmi
@liiight
P. Raj Kumar
@prkumar
@liiight - Thanks for creating the issue! Regarding the workaround not working: I think that's because you are using a dict with the Part annotation. Notably, Part represents one file in the multipart body, so it accepts file object or a tuple containing the part's details . If you need to use a dict, use PartMap instead.
Or Carmi
@liiight
gotcha about the workaround, made it work
thanks!
Or Carmi
@liiight
hey @prkumar , im back :)
so i hit a snag with the register_default_converter_factory workaround
apparantly due to some race condition, or import order, this can override registerd custom json serilizations of other classes
causing a json decode error
commenting out this decorator fixes the other issues but obviously causes the issue at hand not to work
any ideas?
hmm, what if i just create a custom serialization strategy for this specific issue instead of using this default
ill try that. thanks for rubberducking :)
Or Carmi
@liiight
i tried to create a custom serializer using part:
    @multipart
    @patch('/public/watson/datasets/{+dataset_id}')
    def update_dataset(self, dataset_id: str, file: Part(type=EDMFile)):
        """Updates dataset"""
added a dumps.to:
@install
@dumps.to_json(EDMFile)
def report_ep_dumps(_, data: EDMFile):
    return data.name, data.content
but this still fails:
    @staticmethod
    def _default_json_dumper(obj):
>       return obj.__dict__  # pragma: no cover
E       AttributeError: 'bytes' object has no attribute '__dict__'
Or Carmi
@liiight
got a workaround working, i delayed the import of that module into its factory function
Or Carmi
@liiight
@prkumar ping
P. Raj Kumar
@prkumar
@liiight - Hey! Another workaround that should work is to monkey-patch the StandardConverter's create_request_body_convertermethod:
from uplink.converters import StandardConverter

def pass_through_request_body_converter(self, type_, *args, **kwargs):
        return lambda value: value

StandardConverter.create_request_body_converter = pass_through_request_body_converter
Formartha
@Formartha
hi folks, I'm new to uplink and I'm used to requests.. so I find it a bit had to adjust but I see it's future benefits.
how do I construct a request with a parameter in the headers?
P. Raj Kumar
@prkumar
@Formartha - Hi! Glad to welcome you as a new user of uplink! You can find details for how to manipulate the request header here: https://uplink.readthedocs.io/en/stable/user/quickstart.html#header-manipulation
If you want to use an argument as a header, you can use the Header annotation:
@get("user")
def get_user(self, authorization: Header("Authorization")):
    """Get an authenticated user."""
If you want to set a static header, you can use the @headers decorator:
@headers({
    "Accept": "application/vnd.github.v3.full+json",
    "User-Agent": "Uplink-Sample-App"
})
@get("users/{username}")
def get_user(self, username): pass
Vinayak
@vkolgi
Hey @liiight, i hear that you are using uplink for tests. Do you have any specific pointers ? We wanted to use uplink for the same with pytest. @prkumar for the wonderful library
Or Carmi
@liiight
@prkumar thanks for that monkeypatch tip, it actually was really helpful
@vkolgi well, we're basically using uplink for our various apis, and then creating fixtures that return the instantiated classes
nothing too fancy really
Vinayak
@vkolgi
@liiight okay, do you use aiohttp with pytest ? We are trying to see if we can incorporate performance testing as well here, like getting stats from responses and then probably pushing it to elk stack
Rene
@enriquezrene
Hey guys, is there a way to add headers based on a condition. I'd like to add/not-add an authorization header to the same requests based on an env variable
Rene
@enriquezrene
is there any way to log all the executed requests?
P. Raj Kumar
@prkumar
@enriquezrene - For conditionally adding headers, if it's a static header that should be applied (or not applied) to all requests, you could load the environment variable at the top of your module then use the headers decorator:
_custom_headers = {}
if (MY_VAR = os.environ.get('MY_ENVIRONMENT_VARIABLE') == 'some value'):
    _custom_headers['X-MY-CUSTOM-HEADER'] = 'my special value'

# To apply header to all requests, decorate class:
@headers(_custom_headers)
class MyConsumer:
     # or, for a single request, only decorate the method
    @headers(_custom_headers)
    def get_user(self, user):
        pass
P. Raj Kumar
@prkumar

For logging requests: we don't currently expose an easy way to listen to a request before it is sent. I'll create a Github issue to address this!

If this is a blocker for you, you could use the following workaround: listening for requests is technically possible by using a RequestTemplate. You could define your own RequestTemplate subclass and implement the before_request method to log each request sent. For an example of how to define and register a RetryTemplate, you can take a look at the retry decorator. If you decide to take this approach, please let me know if you have any further questions: I'd be more than happy to help! In the future, we can greatly ease this type of use case by exposing a @request_handler decorator. I'll work on that for the next release.

Mike Holler
@mike.holler_gitlab
Hey there, I'm wondering if there's a way I can write a serializer for Pathand Header params, so that a user could, for example, supply a datetime and have it formatted correctly as a query/header param.
Jacob Floyd
@cognifloyd
@prkumar could you release 0.10.0 soon? There's a fix in master and I'd prefer to install from pypi wheels instead of from git. Please and thank you for an amazing library!