juliomalegria / python-craigslist

Simple Craigslist wrapper
MIT No Attribution
387 stars 117 forks source link

ValueError: 'portland' is not a valid site #106

Open chrismdavis opened 3 years ago

chrismdavis commented 3 years ago

Getting the following error including when ran with default site 'sfbay'. Was working as recent as yesterday: Thanks

cl_h = CraigslistHousing(site='portland', category='apa',
                         filters={'max_price': 2000, 
                                  'min_price': 1200,
                                  'posted_today': True,
                                  'search_distance': 15,
                                  'zip_code': 97215,
                                  'housing_type': 'house'})
'portland' is not a valid site
'portland' is not a valid site
'portland' is not a valid site
'portland' is not a valid site
'portland' is not a valid site
Traceback (most recent call last):

  File "<ipython-input-9-da0a94b31916>", line 1, in <module>
    cl_h = CraigslistHousing(site='portland', category='apa',

  File "C:\Users\addas\anaconda3\lib\site-packages\craigslist\base.py", line 63, in __init__
    raise ValueError(msg)

ValueError: 'portland' is not a valid site
irahorecka commented 3 years ago

Hey @chrismd1, so first of all, housing_type is not a valid filter. The resulting url generated by your query is https://portland.craigslist.org/search/apa?searchNearby=1&max_price=2000&min_price=1200&postedToday=1&search_distance=15&postal=97215&s=0

Unfortunately, it seems like Craigslist blocked my IP address (HTTP 403 Forbidden client error). You can try this to see if you have the same results:

import requests
search_url = "https://portland.craigslist.org/search/apa?searchNearby=1&max_price=2000&min_price=1200&postedToday=1&search_distance=15&postal=97215&s=0"

print(requests.get(search_url).status_code)
print(requests.get(search_url).text)

>>> 403
>>> 'This IP has been automatically blocked.\nIf you have questions, please email: blocks-b1613521966357929@craigslist.org\n'
chrismdavis commented 3 years ago

Hi Ira,

Thanks for responding. Of note - the example code from the package information page https://pypi.org/project/python-craigslist/ also returns the same result ('...ValueError: 'sfbay' is not a valid site'). I've removed the 'housetype' filter and still can't avoid this error.

from craigslist import CraigslistHousing

cl_h = CraigslistHousing(site='sfbay', area='sfc', category='roo', filters={'max_price': 1200, 'private_room': True})

You can get an approximate amount of results with the following call:

print(cl_h.get_results_approx_count())

Thanks, Chris

On Wed, Feb 24, 2021 at 10:01 AM Ira Horecka notifications@github.com wrote:

Hey @chrismd1 https://github.com/chrismd1, so first of all, housing_type is not a valid filter. The resulting url generated by your query is https://portland.craigslist.org/search/apa?searchNearby=1&max_price=2000&min_price=1200&postedToday=1&search_distance=15&postal=97215&s=0

Unfortunately, it seems like Craigslist blocked my IP address (HTTP 403 Forbidden client error). You can try this to see if you have the same results:

import requestssearch_url = "https://portland.craigslist.org/search/apa?searchNearby=1&max_price=2000&min_price=1200&postedToday=1&search_distance=15&postal=97215&s=0" print(requests.get(search_url).status_code)print(requests.get(search_url).text)

403>>> 'This IP has been automatically blocked.\nIf you have questions, please email: blocks-b1613521966357929@craigslist.org\n'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/juliomalegria/python-craigslist/issues/106#issuecomment-785264695, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGSL2RJPELJJ4TEUR6RZS23TAU5JHANCNFSM4YE3AJ6A .

irahorecka commented 3 years ago

Hey @chrismd1 I apologize, my maladies was tied with issue #105. Is your issue still persistent?

juliomalegria commented 3 years ago

Hey @chrismd1.

I just tried this and this works just fine for me.

Can you run this to double-check that the library is getting the sites correctly?

In [1]: from craigslist import utils

In [2]: len(utils.get_all_sites())
Out[2]: 708

Can you try that and tell me what you get? Thanks.