401 Error on Each Request

ob1ob1 Posts: 5Member
edited March 5 in Development

We're no longer able to get a successful response from the API. It appears it now just returns the 401 error on any call we make. The code hasn't changed from our side so i'm unsure why it would just stop.

5 comments

  • Alex LugoAlex Lugo Posts: 138Administrator, Lightspeed Staff moderator

    Hello @ob1,

    The error message 401 in most of the occasions indicates that the username/password is not correct, it's quite possible that the password used by the integration has expired, please test the credentials login into Lightspeed

    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • ob1ob1 Posts: 5Member

    Ok that's most likely our issue. We've created a new user and now get the 403 error on all calls.

  • ob1ob1 Posts: 5Member

    Is there a reason we would now be getting 403 errors?

  • Alex LugoAlex Lugo Posts: 138Administrator, Lightspeed Staff moderator

    Hi @ob1 ,

    Would you please send us a copy of the api call and payload used along with the error message?

    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • ob1ob1 Posts: 5Member

    Hi Alex,

    Apologies for the huge delay on coming back to you on this.

    Error Message:

    2019-05-22 13:36:18,343: commencing requests

    2019-05-22 13:36:18,349: Starting new HTTPS connection (1): localhost:9630

    2019-05-22 13:36:18,539: https://localhost:9630 "GET /api/products/?count=1000&offset=0 HTTP/1.1" 403 295

    2019-05-22 13:36:18,540: status code is 403

    Traceback (most recent call last):

     File "working.py", line 34, in <module>

      assert get_response.status_code == 200

    AssertionError


    Code:

    # Setup a session for the http request.

    session = requests.Session()

    session.auth = (ONSITE_USERNAME, ONSITE_PASSWORD)

    session.headers.update({

      'user-agent': '{}/{}'.format(APP_ID, APP_VERSION),

      'x-pappid': APP_PRIVATE_ID

    })

    session.verify = False

    session.stream = True


    output_xml = ET.Element('products')

    products_seen = 0

    logging.info('commencing requests')

    for offset in count(0, PRODUCTS_PER_REQUEST):

      get_response = session.get(PRODUCTS_URL, params={'count': 5, 'offset': offset})

      logging.info('status code is {}'.format(get_response.status_code))

      assert get_response.status_code == 200

      response_xml = ET.fromstring(get_response.text)

      products = response_xml.findall('product')

      if not products:

        break

      num_products = len(products)

      products_seen += num_products

      logging.info('seen {} in batch and {} in total'.format(num_products, products_seen))

      output_xml.extend(products)


    # Log out.

    logout_response = session.post(LOGOUT_URL)

    assert logout_response.status_code == 204

    logging.info('logging out succeeded')

Sign In or Register to comment.