Giter VIP home page Giter VIP logo

lob-python's People

Contributors

ajpawlicki avatar amaan-lob avatar ami avatar amrit avatar bennykitchell avatar bsiddiqui avatar dmlittle avatar elighcash avatar elnaz avatar forbaokhanh avatar graysonchao avatar harry-zhang avatar juanfriss avatar julianpistorius avatar kencrim avatar kilo59 avatar kyleconroy avatar kylekwong avatar leore avatar mrkaspa avatar neelk07 avatar nyergler avatar peterdolan avatar pon avatar robinjoseph08 avatar russelltaylor05 avatar sidchilling avatar sishaarrao avatar sjl2 avatar sudoku-lord avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lob-python's Issues

Python 3?

Hello,

I'm relatively new to Python development, and when I try to import lob into a Python3 project I get

File "/usr/local/opt/pyenv/versions/3.4.2/lib/python3.4/site-packages/lob/__init__.py", line 5, in <module>
    from lob.resource import (Address, Area, BankAccount, Check, Country, Job,
  File "/usr/local/opt/pyenv/versions/3.4.2/lib/python3.4/site-packages/lob/resource.py", line 62
    except KeyError, err:
                   ^
SyntaxError: invalid syntax

Is this because this is a python 2 package? Is there any easy way to port it to python 3?

Thanks

Changelog

Hello,
Do you maintain a change-log somewhere for this library? It is hard to follow the commit history.

Thanks

Cannot retrieve Bank Account Information or Send Checks using lob_python

Getting a failure while attempting to retrieve bank account information in the test environment.

with lob_python.ApiClient(configuration) as lob_client:
    bank_account_id = "xxxxxxxxxx"
    accounts_api = BankAccountsApi(lob_client)

The issue seems to appear when using PNG signature, and occurs due to incorrect regex used to validate signature_url here: https://github.com/lob/lob-python/blob/main/lob_python/model/bank_account.py#L87

Our signature_url looks like so:

https://lob-assets.com/bank-accounts/bank_xxxxxxxxxx_signature.png?ve.....

The regular expression is looking for "thumb" which doesn't appear (there may be additional issues with it).

        ('signature_url',): {
            'regex': {
                'pattern': r'^https:\/\/lob-assets\.com\/(letters|postcards|bank-accounts|checks|self-mailers|cards)\/[a-z]{3,4}_[a-z0-9]{15,16}(\.pdf|_thumb_[a-z]+_[0-9]+\.png)\?(version=[a-z0-9-]*&)?expires=[0-9]{10}&signature=[a-zA-Z0-9-_]+$',  # noqa: E501
            },
        },

This prevents sending of checks as well as the check api seems to use the same validation somewhere in the code path

Add version 5 to pypi if it's ready for usage?

Hi all, thanks for the upgrades to the client!

The last version the client on pypi is 4.5.4, the version on main is version 5 which is a major version bump. Since there are no release notes and pypi is still hosting the previous version of the client, it's unclear on whether version 5 is ready for public consumption already? If it is, would you be able to upload it to pypi?

If I'm not mistaken you should be able to add release notes after the fact here: https://github.com/lob/lob-python/releases/tag/v5.0.0

SyntaxError when importing CreativeWritable

When I import the CreativeWritable class to use it in a api call, I get back the following error:

Traceback (most recent call last):
  File "/Users/sean/dev/minimal-reproduction/main.py", line 1, in <module>
    from lob_python.model.creative_writable import CreativeWritable
  File "/Users/sean/dev/minimal-reproduction/venv/lib/python3.10/site-packages/lob_python/model/creative_writable.py", line 102
    'details': (, PostcardDetailsWritable, type(None)),  # noqa: E501
                ^
SyntaxError: invalid syntax

contents of main.py:

from lob_python.model.creative_writable import CreativeWritable

I have tried importing this class in a python 3.8 project and got the same result. The provided reproduction was done with python 3.10.


Full command line reproduction:

user@machine minimal-reproduction % python3 -m venv venv 
user@machine minimal-reproduction % source venv/bin/activate 
(venv) user@machine minimal-reproduction % pip install lob-python
Collecting lob-python
  Using cached lob-python-5.1.0.tar.gz (172 kB)
  Preparing metadata (setup.py) ... done
Collecting urllib3>=1.25.3
  Using cached urllib3-1.26.14-py2.py3-none-any.whl (140 kB)
Collecting python-dateutil
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting six>=1.5
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: urllib3, six, python-dateutil, lob-python
  DEPRECATION: lob-python is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for lob-python ... done
Successfully installed lob-python-5.1.0 python-dateutil-2.8.2 six-1.16.0 urllib3-1.26.14
(venv) user@machine minimal-reproduction % pip list              
Package         Version
--------------- -------
lob-python      5.1.0
pip             22.3.1
python-dateutil 2.8.2
setuptools      65.6.3
six             1.16.0
urllib3         1.26.14
(venv) user@machine minimal-reproduction % python -c "from lob_python.model.creative_writable import CreativeWritable"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/sean/dev/minimal-reproduction/venv/lib/python3.10/site-packages/lob_python/model/creative_writable.py", line 102
    'details': (, PostcardDetailsWritable, type(None)),  # noqa: E501
                ^
SyntaxError: invalid syntax

Please let me know if you need more information. Thank you.

Cannot upload local files

Current Library does not allow for multi-part file uploads. We are going to be switching the request lib to urllib2 to allow for this.

Importing MultipleComponents or MultipleComponentsList raises SyntaxError

image

from lob_python.models import MultipleComponentsList Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/nick/Code/lob/lob-python/lob_python/models/__init__.py", line 44, in <module> from lob_python.model.campaign import Campaign File "/home/nick/Code/lob/lob-python/lob_python/model/campaign.py", line 32, in <module> from lob_python.model.campaign_creative import CampaignCreative File "/home/nick/Code/lob/lob-python/lob_python/model/campaign_creative.py", line 110 'details': (, PostcardDetailsWritable, type(None)), # noqa: E501 ^ SyntaxError: expression expected after dictionary key and ':'

from lob_python.models import MultipleComponents Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/nick/Code/lob/lob-python/lob_python/models/__init__.py", line 44, in <module> from lob_python.model.campaign import Campaign File "/home/nick/Code/lob/lob-python/lob_python/model/campaign.py", line 32, in <module> from lob_python.model.campaign_creative import CampaignCreative File "/home/nick/Code/lob/lob-python/lob_python/model/campaign_creative.py", line 110 'details': (, PostcardDetailsWritable, type(None)), # noqa: E501

This dict is autogenerated from OpenAPI, but also if you refactor the code, a circular import appears:

image

lob-python 2.3.2 not installing correctly on pypi

It seems that version 2.3.2 that was uploaded to pypi was messed up somehow, presumably by my messing with the version string and trying to make the version more DRY. https://pypi.python.org/pypi/lob/2.3.2

My changes installed successfully to our devpi pypi server at my work, so I'm not sure how to debug this. I'm guessing the easiest solution would be to just revert to using a string literal in setup.py. pypi.python.org seems sort of confused about whether it's 2.3.2 or not (note the missing "Py Version"):
screen shot 2014-09-10 at 7 00 28 pm

How to Reproduce

/tmp $ virtualenv foo && source foo/bin/activate
...
(foo)/tmp $ pip install lob==2.3.2
Downloading/unpacking lob==2.3.2
  Could not find a version that satisfies the requirement lob==2.3.2 (from versions: 2.3, 2.2, 2.1, 2.0, 1.0)
Cleaning up...
No distributions matching the version for lob==2.3.2
Storing debug log for failure in /Users/lucaswiman/.pip/pip.log
(foo)/tmp $ pip install lob==2.3.1
Downloading/unpacking lob==2.3.1
  Could not find a version that satisfies the requirement lob==2.3.1 (from versions: 2.3, 2.2, 2.1, 2.0, 1.0)
Cleaning up...
No distributions matching the version for lob==2.3.1
Storing debug log for failure in /Users/lucaswiman/.pip/pip.log
(foo)/tmp $ pip install lob
Downloading/unpacking lob
  Downloading lob-2.3.tar.gz
  Running setup.py (path:/private/tmp/foo/build/lob/setup.py) egg_info for package lob

Downloading/unpacking requests (from lob)
  Downloading requests-2.3.0-py2.py3-none-any.whl (452kB): 452kB downloaded
Installing collected packages: lob, requests
  Running setup.py install for lob

Successfully installed lob requests
Cleaning up...
(foo)/tmp $ pip freeze
lob==2.3

Is there a way to specify the API key to use on a per-call or per-endpoint basis?

Hello, on my development and staging servers I'm using my publishable API key from production to make US Verification requests (so that they're "real" without actually affecting the real world in any way), while I'm using my secret API key from testing to make Letter requests (so that they don't actually affect the real world).

The only ways I've found to do this are to either subclass the related Resource classes in a way that feels invasive, or to change the value of lob.api_key to its appropriate value before making the request (paying attention to thread safety since it's a global variable). I currently use the latter strategy, but both of these mechanisms feel suboptimal, and I'm curious if there's some other way to do this that I've missed, or if you'd accept PRs to make it easier to do this.

ApiTypeError in last version

Im trying to get this to work but i am receiving many different errors. Is it possible that the version is outdated?

I got this error applying the example in the readme:

raise get_type_error(input_value, path_to_item, valid_classes,
lob_python.exceptions.ApiTypeError: Invalid type for variable 'description'. Required value type is one of [NoneType, str] and passed type was ResourceDescription at ['description']

Add coveralls ingestion to GH actions

Right now, having trouble ingesting our code coverage data into coveralls due to the python code coverage we use not outputting a lcov.info file. We need to look into either finding a way to output a lcov.info file with our current code coverage package or switch to another code coverage service that will ingest xml.

Check validation fails for certain valid amounts, but check is sent anyway

https://github.com/lob/lob-python/blob/main/lob_python/model_utils.py#L918

This line does not correctly determine whether a number is a valid amount. With the imprecision of floating point arithmetic, there will be many cases where dividing a valid amount by 0.01 will result in a non-integer:

>>> 0.14 / 0.01
14.000000000000002
>>> (0.14 / 0.01).is_integer()
False

I scripted a quick test and it seems like 10-20% of valid numbers will fail this check.

Additionally, when I ran into a failed validation, the check was still sent even though the SDK errored.

Parsing a 504 error

Hey guys,
Sometimes we receive a HTTP 504 response error that is not appropriately being caught. In parse_response when you call payload = resp.json(), it will throw a ValueError("No JSON object could be decoded") error.

What I'm thinking of adding before payload = resp.json():

if resp.status_code == 504:
    raise error.APIConnectionError(resp.content,
        resp.content, resp.status_code, resp)

Thoughts? Happy to submit a PR if you think this is good.

None of the postcard tests or examples work

Maybe I'm doing something wrong, but it appears that the code for Postcard doesn't match the documentation in lob or any of the examples in the examples folder.
ipython says the function signature (in lob-python v1.0.0, v1.1, and v1.2) is

lob.Postcard.create(cls, name, to, message=None, back=None, from_address=None, **kwargs)

meaning the example code like this doesn't work at all:

response = lob.Postcard.create(
    to_address={
        'name': 'John Doe',
        'address_line1': '404 Building Apt. 404',
        'address_line2': '',
        'address_city': 'New York',
        'address_state': 'NY',
        'address_zip': '10025',
        'address_country': 'US',
    },
    from_address=None,
    front='http://example.com/front.png',
    back='http://example.com/back.png',
    metadata={
        'id': r.id,
        'specialty': 'abcdefg',
    }
)
Traceback (most recent call last):
  File "<input>", line 20, in <module>
TypeError: create() takes at least 3 arguments (3 given)

Forcing the format results in other weird errors:

response = lob.Postcard.create(
    name='My Test Postcard Mailer',
    to={
        'name': 'John Doe',
        'address_line1': '404 Building Apt. 404',
        'address_line2': '',
        'address_city': 'New York',
        'address_state': 'NY',
        'address_zip': '10025',
        'address_country': 'US',
    },
    from_address=None,
    front='http://example.com/front.png',
    back='http://example.com/back.png',
    metadata={
        'id': r.id,
        'specialty': 'abcdefg',
    }
)
InvalidRequestError: [{u'status_code': 422, u'message': u'metadata must be an object'}]

So then I tried

class MetaData:
    def __init__(self, *args, **kwargs):
        for k, v in kwargs.iteritems():
            setattr(self, k, v)

lob.Postcard.create(..., metadata=Metadata(**{'id': r.id, 'specialty': 'abcdefg'}), ...)

still doesn't work:

AttributeError: MetaData instance has no attribute '__len__'

Any suggestions?

lob API returning 503 throws

After your planned maintenance the other day, can you update /lob/api_requestor.py, parse_response to support 503? Otherwise payload = resp.json() throws.

Ink-Free Area Alignment

Posting here because the /examples repo doesn't have issues enabled.

When using the example 4x6 back template (https://github.com/lob/examples/blob/master/postcards/4x6-back.html), the recipient address / Postage Indicia section is not aligned with the area specified in the template.

I've included a screenshot of the postcard created using the template. I set a black border on the ink-free div in the template to judge where I can place assets. The white address box is about a centimeter off from where it should be according to the template's CSS.

This is obviously easy enough to fix in CSS, but I'm not sure who to trust: the template or the postcard created in test mode.

screen shot 2018-12-20 at 3 12 26 pm

PYPI release

Hi,

I noticed that the latest release to PYPI was back in July of 2013. The version (1.0) does not support file uploads using the files keyword argument, a feature we are relying on. Would it be possible for you to push a new release that contains the current changes in master?

Thanks,

Charlie

PYPI: https://pypi.python.org/pypi/lob-python/1.0

import issue on AWS Lambda

I get this error when trying to import lob on AWS Lambda: Unable to import module 'lambda_function': No module named lob.resource

One thing I'm doing that might be throwing it off is I'm installing the libraries in a subdirectory using this command: pip install -t libs/ lob. There is an __init.py__ file in that libs directory, and that allows me to import other libraries successfully (PyMySQL, braintree, etc.) using from libs import blah. But lob doesn't seem to like being imported that way.

I've attached a .zip of my file structure for reference.

lob_test.zip

Is there a way to specify a timeout for requests?

Hello! I'm using your package in production and would like to provide a timeout value to my Lob requests so that our server doesn't hang. After perusing your source code, it doesn't seem like there's any obvious way to do this, but I'm wondering if I'm missing something, or if you'd accept a PR to add such functionality?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.