HTTP Error 422: Unprocessable Entity when using paged with client.search.code

Open
#96 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
github, python
Domain
api

Research direction

Reproduce the sample using client.search.code and paged, then inspect ghapi/page.py and ghapi/core.py around pagination and request construction. Check the GitHub code-search request constraints to identify why the paged call returns HTTP 422; done means the example paginates successfully and has a regression test for the failing case.

Written by the indexing model from the issue text.

Description

Hey all I am getting the following when running code like the sample I have provided:

import os
from ghapi.all import GhApi
from ghapi.page import paged
from dotenv import load_dotenv
GH_TOKEN = os.getenv('GH_TOKEN', None)

def get_client() -> GhApi:
  """Return the GitHub Client"""
  return GhApi(token=GH_TOKEN)

def search_results(query: str, client: GhApi):
  """Yeilds results pages"""
  search_gen = paged(client.search.code, per_page=100, q=query)

  for results in search_gen:
    yield results

for result in search_results("filename:.dockercfg auth repo:dtaivpp/NewsTicker", get_client()):
    print(result)

Running the above brings me to the following:

Traceback (most recent call last):
File "gh-dorker/dorker.py", line 83, in
main(dorks=args.dorks, search=args.search, scope=args.scope)
File "gh-dorker/dorker.py", line 43, in main
for result in search_results(query, client):
File "gh-dorker/dorker.py", line 24, in search_results
for results in search_gen:
File "/Users/dtippett/Desktop/Software_Projects/gh-dorker/venv/lib/python3.8/site-packages/ghapi/page.py", line 16, in paged
yield from itertools.takewhile(noop, (oper(*args, per_page=per_page, page=i, **kwargs) for i in range(1,max_pages+1)))
File "/Users/dtippett/Desktop/Software_Projects/gh-dorker/venv/lib/python3.8/site-packages/ghapi/page.py", line 16, in
yield from itertools.takewhile(noop, (oper(*args, per_page=per_page, page=i, **kwargs) for i in range(1,max_pages+1)))
File "/Users/dtippett/Desktop/Software_Projects/gh-dorker/venv/lib/python3.8/site-packages/ghapi/core.py", line 63, in call
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "/Users/dtippett/Desktop/Software_Projects/gh-dorker/venv/lib/python3.8/site-packages/ghapi/core.py", line 108, in call
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=self.debug, return_headers=True,
File "/Users/dtippett/Desktop/Software_Projects/gh-dorker/venv/lib/python3.8/site-packages/fastcore/net.py", line 212, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "/Users/dtippett/Desktop/Software_Projects/gh-dorker/venv/lib/python3.8/site-packages/fastcore/net.py", line 113, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None
fastcore.basics.HTTP422UnprocessableEntityError: HTTP Error 422: Unprocessable Entity

Dominant language
Python
Stars
687
Forks
69
Avg merge
1m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AnswerDotAI/ghapi

All issues in AnswerDotAI/ghapi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.