Giter Site home page Giter Site logo

pokemon-tcg-sdk-python's People

Contributors

adback03 avatar cptspacetoaster avatar kirbyuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pokemon-tcg-sdk-python's Issues

Python 3.6 can't connect to "server", certificate verification fails.

Seems like I can't connect to the "server" (or something like that) with python 3.6 getting the error message
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
`During handling of the above exception, another exception occurred:`
Traceback (most recent call last):
File "/Documents/Pokemon/Software/Test.py", line 3, in <module>
card = Card.find('xy1-1')
File "/Documents/Pokemon/Software/pokemontcgsdk/card.py", line 43, in find
return QueryBuilder(Card).find(id)
File "/Documents/Pokemon/Software/pokemontcgsdk/querybuilder.py", line 29, in find
response = RestClient.get(url)[self.type.RESOURCE[:-1]]
File "/Documents/Pokemon/Software/pokemontcgsdk/restclient.py", line 34, in get response = json.loads(urlopen(req).read().decode("utf-8"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>

Process finished with exit code 1

SSL error

Code executed:

from pokemontcgsdk import Card

card = Card.find('xy7-54')
print(card.name)

Error:

ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:645)

Error in Card.find

I am using the SDK to find some cards and I found an error running the following code:

from pokemontcgsdk import RestClient
from pokemontcgsdk import Set
from pokemontcgsdk import Card


API_KEY = "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
RestClient.configure(API_KEY)


# Original card:
#  * 1 Crobat V PR-SW 98
set_from_ptcgo = "PR-SW"
card_number = "98"

sets = Set.where(q=f"ptcgoCode:{set_from_ptcgo}")
set_ = sets[0].id

card_id = set_ + "-" + card_number
print(card_id)
# swshp-98

card = Card.find(card_id)
print(card)
# The previous line returns the following:
"""
Traceback (most recent call last):
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/site-packages/pokemontcgsdk/restclient.py", line 36, in get
    response = json.loads(urlopen(req).read().decode("utf-8"))
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "find_error.py", line 22, in <module>
    card = Card.find(card_id)
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/site-packages/pokemontcgsdk/card.py", line 50, in find
    return QueryBuilder(Card, Card.transform).find(id)
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/site-packages/pokemontcgsdk/querybuilder.py", line 21, in find
    response = RestClient.get(url)['data']
  File "/Users/rodolfoferro/miniforge3/envs/streamlit/lib/python3.8/site-packages/pokemontcgsdk/restclient.py", line 40, in get
    raise PokemonTcgException(err.read())
pokemontcgsdk.restclient.PokemonTcgException: <exception str() failed>
"""

I'm not sure if I'm doing something wrong, but the API is not returning any response for that card.

[ERROR] AttributeError: 'NoneType' object has no attribute 'reverseHolofoil'

As a software engineer,
I want to default the values for the TCGPrices and TCGPlayer objects,
So that there is less chance of Attribute errors.

Background:

I have noticed this exception frequently popping up;
[ERROR] AttributeError: 'NoneType' object has no attribute 'reverseHolofoil'
It appears that the TCGPrices object is None so when the reverseHolofoil property is accessed it throws an exception.

Example with this issue: 'set_code': 'pop4', 'id': '1', 'name': 'Chimecho (Delta Species)'

Proposed Solution:

Default the value of the prices attribute on the TCGPrices object to a TCGPrices object with None values for normal, holofoil, etc.

Default the value of tcgplayer attribute on the Card object to a TCGPlayer object.

@dataclass
class Card():
     ......
     tcgplayer: TCGPlayer = TCGPlayer()

@dataclass
class TCGPlayer():
     ....
    prices: TCGPrices = TCGPrices()

Test Scenarios

  • GIVEN a Card object WHEN I access the tcgplayer attribute THEN the value will always be a TCGPlayer object.
  • GIVEN a TCGPlayer object WHEN I access the prices attribute THEN the value will always be a TCGPrices object.

Python SDK: `select` parameter of `where` forces certain fields to be included

Hi all!

Running into an issue with the where method. If I use the select parameter, I get the following stack trace when including a small subset of fields:

from pokemontcgsdk import Set

Set.where(select="id,name")
DefaultValueNotFoundError                 Traceback (most recent call last)
File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/dacite/core.py:72, in from_dict(data_class, data, config)
     71 try:
---> 72     value = get_default_value_for_field(field, field_type)
     73 except DefaultValueNotFoundError:

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/dacite/dataclasses.py:21, in get_default_value_for_field(field, type_)
     20     return None
---> 21 raise DefaultValueNotFoundError()

DefaultValueNotFoundError: 

During handling of the above exception, another exception occurred:

MissingValueError                         Traceback (most recent call last)
Cell In[30], line 1
----> 1 Set.where(select="id,name")

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/pokemontcgsdk/set.py:30, in Set.where(**kwargs)
     28 @staticmethod
     29 def where(**kwargs):
---> 30     return QueryBuilder(Set).where(**kwargs)

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/pokemontcgsdk/querybuilder.py:40, in QueryBuilder.where(self, **kwargs)
     37 for key, value in kwargs.items():
     38     self.params[key] = value
---> 40 return self.all()

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/pokemontcgsdk/querybuilder.py:63, in QueryBuilder.all(self)
     60 if self.transform:
     61     response = [self.transform(i) for i in response]
---> 63 list.extend([from_dict(self.type, item) for item in response])
     65 if fetch_all:
     66     self.params['page'] += 1

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/dacite/core.py:76, in from_dict(data_class, data, config)
     74         if not field.init:
     75             continue
---> 76         raise MissingValueError(field.name)
     77 if field.init:
     78     init_values[field.name] = value

MissingValueError: missing value for field "images"

If I keep adding fields to the select parameter that are deemed missing in each subsequent stacktrace, I will eventually get a success:

Set.where(select="id,name,images,legalities,printedTotal,releaseDate,series,total,updatedAt")
[
   Set(id='base2', images=SetImage(symbol='https://images.pokemontcg.io/base2/symbol.png', logo='https://images.pokemontcg.io/base2/logo.png'), legalities=Legality(unlimited='Legal', expanded=None, standard=None), name='Jungle', printedTotal=64, ptcgoCode=None, releaseDate='1999/06/16', series='Base', total=64, updatedAt='2020/08/14 09:35:00'),
   Set(id='ecard2', images=SetImage(symbol='https://images.pokemontcg.io/ecard2/symbol.png', logo='https://images.pokemontcg.io/ecard2/logo.png'), legalities=Legality(unlimited='Legal', expanded=None, standard=None), name='Aquapolis', printedTotal=147, ptcgoCode=None, releaseDate='2003/01/15', series='E-Card', total=182, updatedAt='2020/08/14 09:35:00'),
   ...
]

My suspicion is that these fields are mandatory. Does not seem like this functionality is intentional, maybe worth mentioning what fields must be entered by default in the meantime?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.