Giter VIP home page Giter VIP logo

piplapis-python's People

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

Watchers

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

piplapis-python's Issues

Some fields are unsearchable

person = Person()
person.names.append(Name(first='Thalia'))
request = SearchAPIRequest(api_key='SECRET', person=person)
response = request.send()
File "", line 1, in
File "/root/PythonProjects/venv/lib/python3.5/site-packages/piplapis/search.py", line 315, in send
self.validate_query_params(strict=strict_validation)
File "/root/PythonProjects/venv/lib/python3.5/site-packages/piplapis/search.py", line 255, in validate_query_params
raise ValueError('Some fields are unsearchable: %s' % self.person.unsearchable_fields)
ValueError: Some fields are unsearchable: [Name(first='Thalia')]

SearchAPIRequest for raw_name is not working

I am always getting response as empty

Below is the code for reference

from piplapis.search import SearchAPIRequest
from piplapis.data import Person, Name, Address, Job
from piplapis.search import SearchAPIError

request = SearchAPIRequest(raw_name=u'Bill Gates', api_key='zzzzz') // Not working

OR

request = SearchAPIRequest(first_name=u'Bill', last_name=u'Gates', api_key='ZZZZ') // Not working

try:
response = request.send()
except SearchAPIError as e:
print e.http_status_code, e

print(response.name)
print(response.gender)
print(response.education)
print(response.username)
print(response.address)

Anything wrong ?

ValueError: unconverted data remains: T00:00:00

When attempting to use SearchAPIResponse.from_dict, if a date value contains a time it fails. The source of the error is in util.py line 60. I fixed the error by defining:

TIMESTAMP_FORMAT_WITH_TIME = '%Y-%m-%dT%H:%M:%S'

And changing line 60 to read

try:
    return datetime.datetime.strptime(s, TIMESTAMP_FORMAT)
except ValueError:
    return datetime.datetime.strptime(s, TIMESTAMP_FORMAT_WITH_TIME)

Not sure if that's the best solution but I've run into the error multiple times so I figured I'd report it.

Buggy handling of non-json errors from the Pipl API

The code for send() incorrectly assumes that all errors from the Pipl API are JSON, and attempts to decode them, which leads to a further exception, and a verbose exception chain.

Due to this, the caller doesn't receive an exception, and the SearchAPIResponse object is returned as if nothing bad happened, with critical fields such as http_status_code set to None.

It should check if the response is in JSON before attempting to decode it.

Example exception:

ERROR:root:HTTPError: Error fetching data from Pipl
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/piplapis/search.py", line 341, in send
    exception = SearchAPIError.from_json(json_error.decode())
  File "/usr/local/lib/python3.6/site-packages/piplapis/data/utils.py", line 127, in from_json
    d = json.loads(json_str)
  File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/code/syncme/integrations/pipl/search.py", line 440, in __query_pipl
    response = request.send()
  File "/usr/local/lib/python3.6/site-packages/piplapis/search.py", line 345, in send
    raise e
  File "/usr/local/lib/python3.6/site-packages/piplapis/search.py", line 331, in send
    response = urllib2.urlopen(request)
  File "/usr/local/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/local/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 502: Bad Gateway

Problem in SearchAPIResponse.to_dict()

Hi,
Using python 3.4 with the latest piplapis version.

For a certain search I get a crash in:
File "/home/sivanr/env/lib/python3.4/site-packages/piplapis/data/available_data.py", line 17, in to_dict d['premium'] = self.premium.to_dict() File "/home/sivanr/env/lib/python3.4/site-packages/piplapis/data/available_data.py", line 84, in to_dict if getattr(self, child) > 0: TypeError: unorderable types: NoneType() > int()
I looked into this function for debug and found that in certain responses (not always) the result of getattr(self, child) returns None, hence the error message.
Please check if the problem is that a result of getattr is None or that this function should support this and check in advance.

Syntax warnings with Python 3.12 - invalid escape sequences.

The following regular expressions produce syntax warnings with Python 3.12:

piplapis/data/fields.py:398: SyntaxWarning: invalid escape sequence '\-'
  re_email = re.compile("^[a-zA-Z0-9'._%\-+]+@[a-zA-Z0-9._%\-]+\.[a-zA-Z]{2,24}$")
piplapis/data/fields.py:576: SyntaxWarning: invalid escape sequence '\d'
  tokens = ",".join([re.sub("&dsid=\d+", "", x.thumbnail_token) for x in images_with_tokens])
piplapis/data/utils.py:109: SyntaxWarning: invalid escape sequence '\:'
  VALID_URL_REGEX = re.compile('^(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?$')

Since these are not valid string escape sequences, the \ should be escaped with another \, or the whole string should be marked raw with r''.
This used to be a DeprecationWarning, and has now been upgraded to a SyntaxWarning.

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.