Invalid Response using client.checkins.add
Closed this issue · 3 comments
I am using an OAuth token I generated myself and looked up some venues. I selected one of the venues and created a checkin but it is returning HTML output. The result is the same if I use client ID and client secret.
`
import foursquare
client = foursquare.Foursquare(access_token='**********')
print(client.venues.search(params={'ll':'21.39517,-158.01317'}))
print(client.checkins.add(params={'venuId':'4bf58dd8d48988d103941735','shout':'TEST'}))
`
When I run it, I get the list of venues, but the checkin portion returns the following
Traceback (most recent call last): File "test.py", line 9, in <module> print(client.checkins.add(params={'venuId':'4bf58dd8d48988d103941735','shout':'TEST'})) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 498, in add return self.POST('add', params) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 274, in POST return self.requester.POST(self._expanded_path(path), *args, **kwargs) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 231, in POST result = _post(url, headers=headers, data=data, files=files) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 772, in _post return _process_response(response) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 782, in _process_response _log_and_raise_exception('Invalid response', response.text) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 746, in _log_and_raise_exception raise cls(u'{0}: {1}'.format(msg, data)) foursquare.FoursquareException: Invalid response: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Access to this page has been denied.</title> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <style> html, body { margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; color: #000; } a { color: #c5c5c5; text-decoration: none; } .container { align-items: center; display: flex; flex: 1; justify-content: space-between; flex-direction: column; height: 100%; } .container > div { width: 100%; display: flex; justify-content: center; } .container > div > div { display: flex; width: 80%; } .customer-logo-wrapper { padding-top: 2rem; flex-grow: 0; background-color: #fff; visibility: hidden; } .customer-logo { border-bottom: 1px solid #000; } .customer-logo > img { padding-bottom: 1rem; max-height: 50px; max-width: 100%; } .page-title-wrapper { flex-grow: 2; } .page-title { flex-direction: column-reverse; } .content-wrapper { flex-grow: 5; } .content { flex-direction: column; } .page-footer-wrapper { align-items: center; flex-grow: 0.2; background-color: #000; color: #c5c5c5; font-size: 70%; } @media (min-width: 768px) { html, body { height: 100%; } } </style> <!-- Custom CSS --> </head> <body> <section class="container"> <div class="customer-logo-wrapper"> <div class="customer-logo"> <img src="" alt="Logo"/> </div> </div> <div class="page-title-wrapper"> <div class="page-title"> <h1>Please verify you are a human</h1> </div> </div> <div class="content-wrapper"> <div class="content"> <div id="px-captcha"> </div> <p> Access to this page has been denied because we believe you are using automation tools to browse the website. </p> <p> This may happen as a result of the following: </p> <ul> <li> Javascript is disabled or blocked by an extension (ad blockers for example) </li> <li> Your browser does not support cookies </li> </ul> <p> Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading. </p> <p> Reference ID: #fe460690-d4d7-11e9-95a1-cda852344b38 </p> </div> </div> <div class="page-footer-wrapper"> <div class="page-footer"> <p> Powered by <a href="https://www.perimeterx.com/whywasiblocked">PerimeterX</a> , Inc. </p> </div> </div> </section> <!-- Px --> <script> window._pxAppId = 'PX0UqK4c76'; window._pxJsClientSrc = '/0UqK4c76/init.js'; window._pxFirstPartyEnabled = true; window._pxVid = ''; window._pxUuid = 'fe460690-d4d7-11e9-95a1-cda852344b38'; window._pxHostUrl = '/0UqK4c76/xhr'; </script> <script src="/0UqK4c76/captcha/captcha.js?a=c&u=fe460690-d4d7-11e9-95a1-cda852344b38&v=&m=0"></script> <!-- Custom Script --> </body> </html>
Try fixing the typo in your params: venuId
Fixed to print(client.checkins.add(params={'venueId':'4bf58dd8d48988d103941735','shout':'TEST'}))
But still getting
Traceback (most recent call last): File "test.py", line 9, in <module> print(client.checkins.add(params={'venueId':'4bf58dd8d48988d103941735','shout':'TEST'})) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 498, in add return self.POST('add', params) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 274, in POST return self.requester.POST(self._expanded_path(path), *args, **kwargs) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 231, in POST result = _post(url, headers=headers, data=data, files=files) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 772, in _post return _process_response(response) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 782, in _process_response _log_and_raise_exception('Invalid response', response.text) File "/home/dolfin/.local/lib/python2.7/site-packages/foursquare/__init__.py", line 746, in _log_and_raise_exception raise cls(u'{0}: {1}'.format(msg, data)) foursquare.FoursquareException: Invalid response: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Access to this page has been denied.</title> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <style> html, body { margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; color: #000; } a { color: #c5c5c5; text-decoration: none; } .container { align-items: center; display: flex; flex: 1; justify-content: space-between; flex-direction: column; height: 100%; } .container > div { width: 100%; display: flex; justify-content: center; } .container > div > div { display: flex; width: 80%; } .customer-logo-wrapper { padding-top: 2rem; flex-grow: 0; background-color: #fff; visibility: hidden; } .customer-logo { border-bottom: 1px solid #000; } .customer-logo > img { padding-bottom: 1rem; max-height: 50px; max-width: 100%; } .page-title-wrapper { flex-grow: 2; } .page-title { flex-direction: column-reverse; } .content-wrapper { flex-grow: 5; } .content { flex-direction: column; } .page-footer-wrapper { align-items: center; flex-grow: 0.2; background-color: #000; color: #c5c5c5; font-size: 70%; } @media (min-width: 768px) { html, body { height: 100%; } } </style> <!-- Custom CSS --> </head> <body> <section class="container"> <div class="customer-logo-wrapper"> <div class="customer-logo"> <img src="" alt="Logo"/> </div> </div> <div class="page-title-wrapper"> <div class="page-title"> <h1>Please verify you are a human</h1> </div> </div> <div class="content-wrapper"> <div class="content"> <div id="px-captcha"> </div> <p> Access to this page has been denied because we believe you are using automation tools to browse the website. </p> <p> This may happen as a result of the following: </p> <ul> <li> Javascript is disabled or blocked by an extension (ad blockers for example) </li> <li> Your browser does not support cookies </li> </ul> <p> Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading. </p> <p> Reference ID: #2bb2cea0-d4f7-11e9-804a-d52cc56045bd </p> </div> </div> <div class="page-footer-wrapper"> <div class="page-footer"> <p> Powered by <a href="https://www.perimeterx.com/whywasiblocked">PerimeterX</a> , Inc. </p> </div> </div> </section> <!-- Px --> <script> window._pxAppId = 'PX0UqK4c76'; window._pxJsClientSrc = '/0UqK4c76/init.js'; window._pxFirstPartyEnabled = true; window._pxVid = ''; window._pxUuid = '2bb2cea0-d4f7-11e9-804a-d52cc56045bd'; window._pxHostUrl = '/0UqK4c76/xhr'; </script> <script src="/0UqK4c76/captcha/captcha.js?a=c&u=2bb2cea0-d4f7-11e9-804a-d52cc56045bd&v=&m=0"></script> <!-- Custom Script --> </body> </html>
K, that endpoint is working fine for me in the test suite.
You are likely getting blocked by 4sq's servers for excessive API requests. Alternatively, if you're accessing from public internet or a VPN, that IP could have been restricted in the past.
Follow the link in the response for more info on why you might have gotten blocked.