#๐Ÿ”’ invalid start byte on generated data

54 messages ยท Page 1 of 1 (latest)

cunning zinc
#

im working on generating files to work with an api in a local way since all of the data is public anyway and itd be nice to just be able to access it like any other game data.

https://github.com/BigBrainTime/tinys-srd

im getting the error in multiple files and i cant figure out why.
test.py is where im getting the error on just trying to import the module

GitHub

Contribute to BigBrainTime/tinys-srd development by creating an account on GitHub.

thorny quartzBOT
#

@cunning zinc

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cunning zinc
#

classes/bard/starting-equipment-options is where the first error occurs, and ive tried writing the files in multiple ways but the bug persists

fair wing
#

Can you paste the full error?

cunning zinc
#
  File "e:\Documents\CodingProjects\5eAPIclassthing\tinys-srd\dnd_api\Classes.py", line 5
    ion. You use your Charisma whenever a spell refers to your spellcasting ability. In addition, you use your Charisma modifier when setting the saving throw DC for a bard spell you cast and when making an attack roll with one.', 'Spell save DC = 8 + your proficiency bonus + your Charisma modifier.', 'Spell attack modifier = your proficiency bonus + your Charisma modifier.']}, {'name': 'Ritual Casting', 'desc': ['You can cast any bard spell you know as a ritual if that spell has the ritual tag.']}, {'name': 'Spellcasting Focus', 'desc': ['You can use a musical instrument (see Equipment) as a spellcasting focus for your bard spells.']}]},spells = '/api/classes/bard/spells',url = '/api/classes/bard')




                                                ^
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0x92 in position 14: invalid start byte
#

oh wait, this error is in a different place than before i guess the new format moved it

#

but there are still multiple of the same error throughout

fair wing
#

I don't think that's UTF-8

#

try cp1252

cunning zinc
#
import requests
import json

url = "https://raw.githubusercontent.com/5e-bits/5e-database/main/src/5e-SRD-"
suffix = ".json"

files = ["Ability-Scores","Alignments","Backgrounds","Classes","Conditions","Damage-Types","Equipment-Categories","Equipment","Feats","Features","Languages","Levels","Magic-Items","Magic-Schools","Monsters","Proficiencies","Races","Rule-Sections","Rules","Skills","Spells","Subclasses","Subraces","Traits","Weapon-Properties"]

for file in files:
    print(file)
    data = requests.get(f"{url}{file}{suffix}").json()

    with open(f"data/{file}{suffix}", "w") as out:
        json.dump(data, out, indent = 2)
``` this is how im downloading the files the data comes from i think this would the best place to check right>
fair wing
#

That file Classes.py appears to be using โ€™ instead of '

cunning zinc
#

yup, which is caught later on in the generation so when its called it shouldnt even exist

#

unless my code misses a few

cunning zinc
fair wing
#

CP1252 is Windows Codepage 1252

cunning zinc
#

yeah i understand what it is but im struggling to convert even with this guide XD

#

im a bit out of practice after not being able to do anything for a month XD

#

this was supposed to be a 1 day project to get me back into the feel of things

fair wing
#

Firefox search isn't doing me any favors. It's finding either ' or โ€™ when I search for either.

#

Is that the full error?

cunning zinc
#

ill take a closer look at it, bc the original data does

#

and thats the whole error thats given to me

fair wing
#

requests just sort of guesses at the encoding

#

Sometimes it gets it wrong.

cunning zinc
#

so when i request the data and get the text of it the apostrophe comes as a big ? but converting to json gives me \u2019 which i then replace while writing the files

fair wing
#

Usually it's just somebody screwing up on the other end though.

cunning zinc
#

its a passion project for good sized group so maybe i can make a pull request to fix it if its something on their end

fair wing
#

Is tinys-srd yours?

cunning zinc
#

yes

fair wing
#

cool I was going to ask. I found the SRD in Markdown on github

#

They appear to have a Discord. You could ask there.

cunning zinc
#

i did XD i actually made their discord bot for them

fair wing
#

Cool, then you have a rapport.

cunning zinc
#

they dont know whats going on either and are guessing at encoding issue on my end

#

this was my second stop

#

been talking with them about it 2-3 days i think

fair wing
#

Wish I could be more help.

#

Good luck.

cunning zinc
#

you were plenty help, you gave me a lead on something

#

ofc it doesnt lol

#
for file in files:
    print(file)
    data = requests.get(f"{url}{file}{suffix}")
    print(data.encoding,1)
    data.encoding = data.apparent_encoding
    print(data.encoding, 2)
Ability-Scores
utf-8 1
ascii 2
Alignments
utf-8 1
ascii 2
Backgrounds
utf-8 1
ascii 2
Classes
utf-8 1
utf-8 2
Conditions
utf-8 1
ascii 2
Damage-Types
utf-8 1
ascii 2
Equipment-Categories
utf-8 1
utf-8 2
Equipment
utf-8 1
ascii 2
Feats
utf-8 1
utf-8 2
Features
utf-8 1
ascii 2
Languages
utf-8 1
ascii 2
Levels
utf-8 1
ascii 2
Magic-Items
utf-8 1
utf-8 2
Magic-Schools
utf-8 1
ascii 2
Monsters
utf-8 1
utf-8 2
Proficiencies
utf-8 1
ascii 2
Races
utf-8 1
utf-8 2
Rule-Sections
utf-8 1
utf-8 2
Rules
utf-8 1
ascii 2
Skills
utf-8 1
ascii 2
Spells
utf-8 1
ascii 2
Subclasses
utf-8 1
ascii 2
Subraces
utf-8 1
ascii 2
Traits
utf-8 1
ascii 2
Weapon-Properties
utf-8 1
ascii 2
#

it does however provide a look into what chardet thinks things are

#
for file in files:
    print(file)
    data = requests.get(f"{url}{file}{suffix}")
    data.encoding = 'cp1252'

    with open(f"data/{file}{suffix}", "w") as out:
        out.write(data.text)

manually setting it fixed the error

#

@fair wing you telling me the likely format saved the day lol all errors gone

fair wing
#

๐Ÿ‘

#

glad you got it figured out

cunning zinc
#

!close

thorny quartzBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.