Python Forum
unusual error in printing result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unusual error in printing result
#1
I want to print the names of the people in the url with which it is capturing from the webpage from another python file.This is how I have provided the defination of the class which I am not supposed to change
datatracker.py
 def people(self, since="1970-01-01T00:00:00", until="2038-01-19T03:14:07", name_contains=None):
        """
        A generator that returns people recorded in the datatracker. As of April
        2018, there are approximately 21500 people recorded.
        Parameters:
            since         -- Only return people with timestamp after this
            until         -- Only return people with timestamp before this
            name_contains -- Only return peopls whose name containing this string
        Returns:
            An iterator, where each element is as returned by the person() method
        """
        url = self.base_url + "/api/v1/person/person/?time__gt=" + since + "&time__lt=" + until
        if name_contains is not None:
            url = url + "&name__contains=" + name_contains
        while url is not None:
            r = self.session.get(url, verify=True)
            meta = r.json()['meta']
            objs = r.json()['objects']
            url = meta['next']
            for obj in objs:
                yield obj
The person class is as shown below:
@dataclass
class Person:
    resource_uri: str
    id: int
    name: str
    name_from_draft: str
    ascii: str
    ascii_short: Optional[str]
    user: str
    time: str
    photo: str
    photo_thumb: str
    biography: str
    consent: bool
I have to write another python code which would call this function and give me the names of the people
I tried writing the code to print the result in another python file as shown below, but it threw an error although I was able to get the names

app.py
import requests
import datatracker
import rfcindex
user=datatracker.DataTracker()
user_people = user.people("1970-01-01T00:00:00", "2038-01-19T03:14:07", "")
 for u in user_people:
    print(u['name'])
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '/api/v1/person/person/?limit=20&name__contains=&time__gt=2010-01-01&time__lt=2020-01-01&offset=20': No schema supplied. Perhaps you meant http:///api/v1/person/person/?limit=20&name__contains=&time__gt=2010-01-01&time__lt=2020-01-01&offset=20?

Please help
Reply
#2
(Jul-17-2019, 10:20 PM)janaki26794 Wrote:
       url = self.base_url + "/api/v1/person/person/?time__gt=" + since + "&time__lt=" + until

(Jul-17-2019, 10:20 PM)janaki26794 Wrote:
Error:
raise MissingSchema(error) requests.exceptions.MissingSchema: Invalid URL '/api/v1/person/person/?limit=20&name__contains=&time__gt=2010-01-01&time__lt=2020-01-01&offset=20': No schema supplied.

Looks like self.base_url doesn't have a value.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020