Как объявить базовую модель Pydantic в FastAPI, чтобы получить действительный объект json в одном из ее ключей?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как объявить базовую модель Pydantic в FastAPI, чтобы получить действительный объект json в одном из ее ключей?

Сообщение Anonymous »

Клиентское приложение отправляет данные на сервер методом POST. Данные в основном имеют 4 пары ключ-значение, из которых значение второго ключа является действительным объектом json с несколькими парами ключ-значение в нем. Сейчас это выглядит так:

Код: Выделить всё

{
"name": "string",
"content":  {{"resolution":"1","symbol_type":"stock","exchange":"NSE","listed_exchange":"","symbol":"NSE:SBIN-EQ","short_name":"SBIN","legs":"[{\"symbol\":\"SBIN\",\"pro_symbol\":\"SBIN\"}]","name":"asdwa","description":"","charts_symbols":"{\"1\":{\"symbol\":\"NSE:SBIN-EQ\"}}","is_realtime":"1","content":"{\"name\":\"asdwa\",\"layout\":\"s\",\"charts\":[{\"panes\":[{\"sources\":[{\"type\":\"MainSeries\",\"id\":\"RGTnHz\",\"state\":{\"style\":1,\"esdShowDividends\":true,\"esdShowSplits\":true,\"esdShowEarnings\":true,\"esdShowBreaks\":false,\"esdFlagSize\":2,\"showCountdown\":false,\"bidAsk\":{\"visible\":false,\"lineStyle\":1,\"lineWidth\":1,\"bidLineColor\":\"#2962FF\",\"askLineColor\":\"#EF5350\"},\"prePostMarket\":{\"visible\":true,\"lineStyle\":1,\"lineWidth\":1,\"preMarketColor\":\"#fb8c00\",\"postMarketColor\":\"#2962FF\"},\"highLowAvgPrice\":{\"highLowPriceLinesVisible\":false,\"highLowPriceLabelsVisible\":false,\"averageClosePriceLineVisible\":false,\"averageClosePriceLabelVisible\":false},\"showInDataWindow\":true,\"visible\":true,\"showPriceLine\":true,\"priceLineWidth\":1,\"priceLineColor\":\"\",\"baseLineColor\":\"#B2B5BE\",\"showPrevClosePriceLine\":false,\"prevClosePriceLineWidth\":1,\"prevClosePriceLineColor\":\"rgba( 85, 85, 85, 1)\",\"minTick\":\"default\",\"dividendsAdjustment\":{},\"sessionId\":\"regular\",\"sessVis\":false,\"statusViewStyle\":{\"fontSize\":16,\"showExchange\":true,\"showInterval\":true,\"symbolTextSource\":\"description\"},\"candleStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"drawWick\":true,\"drawBorder\":true,\"borderColor\":\"#378658\",\"borderUpColor\":\"#26a69a\",\"borderDownColor\":\"#ef5350\",\"wickColor\":\"#737375\",\"wickUpColor\":\"#26a69a\",\"wickDownColor\":\"#ef5350\",\"barColorsOnPrevClose\":false,\"drawBody\":true},\"hollowCandleStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"drawWick\":true,\"drawBorder\":true,\"borderColor\":\"rgba( 55, 134, 88, 1)\",\"borderUpColor\":\"#26a69a\",\"borderDownColor\":\"#ef5350\",\"wickColor\":\"rgba( 115, 115, 117, 1)\",\"wickUpColor\":\"#26a69a\",\"wickDownColor\":\"#ef5350\",\"drawBody\":true},\"haStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"drawWick\":true,\"drawBorder\":true,\"borderColor\":\"rgba( 55, 134, 88, 1)\",\"borderUpColor\":\"#26a69a\",\"borderDownColor\":\"#ef5350\",\"wickColor\":\"rgba( 115, 115, 117, 1)\",\"wickUpColor\":\"#26a69a\",\"wickDownColor\":\"#ef5350\",\"showRealLastPrice\":false,\"barColorsOnPrevClose\":false,\"inputs\":{},\"inputInfo\":{},\"drawBody\":true},\"barStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"barColorsOnPrevClose\":false,\"dontDrawOpen\":false,\"thinBars\":true},\"hiloStyle\":{\"color\":\"#2962FF\",\"showBorders\":true,\"borderColor\":\"#2962FF\",\"showLabels\":true,\"labelColor\":\"#2962FF\",\"fontSize\":7,\"drawBody\":true},\"lineStyle\":{\"color\":\"#2962FF\",\"linestyle\":0,\"linewidth\":2,\"priceSource\":\"close\",\"styleType\":2},\"areaStyle\":{\"color1\":\"rgba(41, 98, 255,  0.28)\",\"color2\":\"#2962FF\",\"linecolor\":\"#2962FF\",\"linestyle\":0,\"linewidth\":2,\"priceSource\":\"close\",\"transparency\":100},\"renkoStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"borderUpColor\":\"#26a69a\",\"borderDownColor\":\"#ef5350\",\"upColorProjection\":\"rgba( 169, 220, 195, 1)\",\"downColorProjection\":\"rgba( 245, 166, 174, 1)\",\"borderUpColorProjection\":\"rgba( 169, 220, 195, 1)\",\"borderDownColorProjection\":\"rgba( 245, 166, 174, 1)\",\"wickUpColor\":\"#26a69a\",\"wickDownColor\":\"#ef5350\",\"inputs\":{\"source\":\"close\",\"sources\":\"Close\",\"boxSize\":3,\"style\":\"ATR\",\"atrLength\":14,\"wicks\":true},\"inputInfo\":{\"source\":{\"name\":\"source\"},\"sources\":{\"name\":\"Source\"},\"boxSize\":{\"name\":\"Box size\"},\"style\":{\"name\":\"Style\"},\"atrLength\":{\"name\":\"ATR length\"},\"wicks\":{\"name\":\"Wicks\"}}},\"pbStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"borderUpColor\":\"#26a69a\",\"borderDownColor\":\"#ef5350\",\"upColorProjection\":\"rgba( 169, 220, 195, 1)\",\"downColorProjection\":\"rgba( 245, 166, 174, 1)\",\"borderUpColorProjection\":\"rgba( 169, 220, 195, 1)\",\"borderDownColorProjection\":\"rgba( 245, 166, 174, 1)\",\"inputs\":{\"source\":\"close\",\"lb\":3},\"inputInfo\":{\"source\":{\"name\":\"Source\"},\"lb\":{\"name\":\"Number of line\"}}},\"kagiStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"upColorProjection\":\"rgba( 169, 220, 195, 1)\",\"downColorProjection\":\"rgba( 245, 166, 174, 1)\",\"inputs\":{\"source\":\"close\",\"style\":\"ATR\",\"atrLength\":14,\"reversalAmount\":1},\"inputInfo\":{\"source\":{\"name\":\"Source\"},\"style\":{\"name\":\"Style\"},\"atrLength\":{\"name\":\"ATR length\"},\"reversalAmount\":{\"name\":\"Reversal amount\"}}},\"pnfStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"upColorProjection\":\"rgba( 169, 220, 195, 1)\",\"downColorProjection\":\"rgba( 245, 166, 174, 1)\",\"inputs\":{\"sources\":\"Close\",\"reversalAmount\":3,\"boxSize\":1,\"style\":\"ATR\",\"atrLength\":14,\"oneStepBackBuilding\":false},\"inputInfo\":{\"sources\":{\"name\":\"Source\"},\"boxSize\":{\"name\":\"Box size\"},\"reversalAmount\":{\"name\":\"Reversal amount\"},\"style\":{\"name\":\"Style\"},\"atrLength\":{\"name\":\"ATR length\"},\"oneStepBackBuilding\":{\"name\":\"One step back building\"}}},\"baselineStyle\":{\"baselineColor\":\"rgba( 117, 134, 150, 1)\",\"topFillColor1\":\"rgba( 38, 166, 154, 0.28)\",\"topFillColor2\":\"rgba( 38, 166, 154, 0.05)\",\"bottomFillColor1\":\"rgba( 239, 83, 80, 0.05)\",\"bottomFillColor2\":\"rgba( 239, 83, 80, 0.28)\",\"topLineColor\":\"rgba( 38, 166, 154, 1)\",\"bottomLineColor\":\"rgba( 239, 83, 80, 1)\",\"topLineWidth\":2,\"bottomLineWidth\":2,\"priceSource\":\"close\",\"transparency\":50,\"baseLevelPercentage\":50},\"rangeStyle\":{\"upColor\":\"#26a69a\",\"downColor\":\"#ef5350\",\"thinBars\":true,\"upColorProjection\":\"rgba( 169, 220, 195, 1)\",\"downColorProjection\":\"rgba( 245, 166, 174,  1 ) \ & q u o t ; , \ & q u o t ; i n p u t s \ & q u o t ; : { \ & q u o t ; r a n g e \ & q u o t ; : 1 0 , \ & q u o t ; p h a n t o m B a r s \ & q u o t ; : f a l s e } , \ & q u o t ; i n p u t I n f o \ & q u o t ; : { \ & q u o t ; r a n g e \ & q u o t ; : { \ & q u o t ; n a m e \ & q u o t ; : \ & q u o t ; R a n g e \ & q u o t ; } , \ & q u o t ; p h a n t o m B a r s \ & q u o t ; : { \ & q u o t ; n a m e \ & q u o t ; : \ & q u o t ; P h a n t o m   b a r s \ & q u o t ; } } } , \ & q u o t ; s y m b o l \ & q u o t ; : \ & q u o t ; N S E : S B I N - E Q \ & q u o t ; , \ & q u o t ; s h o r t N a m e \ & q u o t ; : \ & q u o t ; S B I N \ & q u o t ; , \ & q u o t ; t i m e f r a m e \ & q u o t ; : \ & q u o t ; \ & q u o t ; , \ & q u o t ; o n W i d g e t \ & q u o t ; : f a l s e , \ & q u o t ; i n t e r v a l \ & q u o t ; : \ & q u o t ; 1 \ & q u o t ; , \ & q u o t ; u n i t I d \ & q u o t ; : n u l l , \ & q u o t ; c u r r e n c y I d \ & q u o t ; : n u l l , \ & q u o t ; p r i c e A x i s P r o p e r t i e s \ & q u o t ; : { \ & q u o t ; a u t o S c a l e \ & q u o t ; : t r u e , \ & q u o t ; a u t o S c a l e D i s a b l e d \ & q u o t ; : f a l s e , \ & q u o t ; l o c k S c a l e \ & q u o t ; : f a l s e , \ & q u o t ; p e r c e n t a g e \ & q u o t ; : f a l s e , \ & q u o t ; p e r c e n t a g e D i s a b l e d \ & q u o t ; : f a l s e , \ & q u o t ; l o g \ & q u o t ; : f a l s e , \ & q u o t ; l o g D i s a b l e d \ & q u o t ; : f a l s e , \ & q u o t ; a l i g n L a b e l s \ & q u o t ; : t r u e , \ & q u o t ; i s I n v e r t e d \ & q u o t ; : f a l s e , \ & q u o t ; i n d e x e d T o 1 0 0 \ & q u o t ; : f a l s e } } , \ & q u o t ; z o r d e r \ & q u o t ; : 0 , \ & q u o t ; h a S t y l e \ & q u o t ; : { \ & q u o t ; s t u d y I d \ & q u o t ; : \ & q u o t ; B a r S e t H e i k e n A s h i @ t v - b a s i c s t u d i e s - 6 0 \ & q u o t ; } , \ & q u o t ; r e n k o S t y l e \ & q u o t ; : { \ & q u o t ; s t u d y I d \ & q u o t ; : \ & q u o t ; B a r S e t R e n k o @ t v - p r o s t u d i e s - 4 0 \ & q u o t ; } , \ & q u o t ; p b S t y l e \ & q u o t ; : { \ & q u o t ; s t u d y I d \ & q u o t ; : \ & q u o t ; B a r S e t P r i c e B r e a k @ t v - p r o s t u d i e s - 3 4 \ & q u o t ; } , \ & q u o t ; k a g i S t y l e \ & q u o t ; : { \ & q u o t ; s t u d y I d \ & q u o t ; : \ & q u o t ; B a r S e t K a g i @ t v - p r o s t u d i e s - 3 4 \ & q u o t ; } , \ & q u o t ; p n f S t y l e \ & q u o t ; : { \ & q u o t ; s t u d y I d \ & q u o t ; : \ & q u o t ; B a r S e t P n F @ t v - p r o s t u d i e s - 3 4 \ & q u o t ; } , \ & q u o t ; r a n g e S t y l e \ & q u o t ; : { \ & q u o t ; s t u d y I d \ & q u o t ; : \ & q u o t ; B a r S e t R a n g e @ t v - b a s i c s t u d i e s - 7 2 \ & q u o t ; } } , { \ & q u o t ; t y p e \ & q u o t ; : \ & q u o t ; s t u d y _ V o l u m e \ & q u o t ; , \ & q u o t ; i d \ & q u o t ; : \ & q u o t ; b l 7 j k V \ & q u o t ; , \ & q u o t ; s t a t e \ & q u o t ; : { \ & q u o t ; s t y l e s \ & q u o t ; : { \ & q u o t ; v o l \ & q u o t ; : { \ & q u o t ; l i n e s t y l e \ & q u o t ; : 0 , \ & q u o t ; l i n e w i d t h \ & q u o t ; : 1 , \ & q u o t ; p l o t t y p e \ & q u o t ; : 5 , \ & q u o t ; t r a c k P r i c e \ & q u o t ; : f a l s e , \ & q u o t ; t r a n s p a r e n c y \ & q u o t ; : 5 0 , \ & q u o t ; v i s i b l e \ & q u o t ; : t r u e , \ & q u o t ; c o l o r \ & q u o t ; : \ & q u o t ; # 0 0 0 0 8 0 \ & q u o t ; , \ & q u o t ; h i s t o g r a m B a s e \ & q u o t ; : 0 , \ & q u o t ; j o i n P o i n t s \ & q u o t ; : f a l s e , \ & q u o t ; t i t l e \ & q u o t ; : \ & q u o t ; V o l u m e \ & q u o t ; } , \ & q u o t ; v o l _ m a \ & q u o t ; : { \ & q u o t ; l i n e s t y l e \ & q u o t ; : 0 , \ & q u o t ; l i n e w i d t h \ & q u o t ; : 1 , \ & q u o t ; p l o t t y p e \ & q u o t ; : 0 , \ & q u o t ; t r a c k P r i c e \ & q u o t ; : f a l s e , \ & q u o t ; t r a n s p a r e n c y \ & q u o t ; : 0 , \ & q u o t ; v i s i b l e \ & q u o t ; : f a l s e , \ & q u o t ; c o l o r \ & q u o t ; : \ & q u o t ; # 2 1 9 6 f 3 \ & q u o t ; , \ & q u o t ; h i s t o g r a m B a s e \ & q u o t ; : 0 , \ & q u o t ; j o i n P o i n t s \ & q u o t ; : f a l s e , \ & q u o t ; t i t l e \ & q u o t ; : \ & q u o t ; V o l u m e   M A \ & q u o t ; } } , \ & q u o t ; p a l e t t e s \ & q u o t ; : { \ & q u o t ; v o l u m e P a l e t t e \ & q u o t ; : { \ & q u o t ; c o l o r s \ & q u o t ; : { \ & q u o t ; 0 \ & q u o t ; : { \ & q u o t ; c o l o r \ & q u o t ; : \ & q u o t ; # E F 5 3 5 0 \ & q u o t ; , \ & q u o t ; w i d t h \ & q u o t ; : 1 , \ & q u o t ; s t y l e \ & q u o t ; : 0 , \ & q u o t ; n a m e \ & q u o t ; : \ & q u o t ; F a l l i n g \ & q u o t ; } , \ & q u o t ; 1 \ & q u o t ; : { \ & q u o t ; c o l o r \ & q u o t ; : \ & q u o t ; # 2 6 A 6 9 A \ & q u o t ; , \ & q u o t ; w i d t h \ & q u o t ; : 1 , \ & q u o t ; s t y l e \ & q u o t ; : 0 , \ & q u o t ; n a m e \ & q u o t ; : \ & q u o t ; G r o w i n g \ & q u o t ; } } } } , \ & q u o t ; i n p u t s \ & q u o t ; : { \ & q u o t ; s h o w M A \ & q u o t ; : f a l s e , \ & q u o t ; l e n g t h \ & q u o t ; : 2 0 , \ & q u o t ; c o l _ p r e v _ c l o s e \ & q u o t ; : f a l s e } , \ & q u o t ; p r e c i s i o n \ & q u o t ; : \ & q u o t ; d e f a u l t \ & q u o t ; , \ & q u o t ; b a n d s \ & q u o t ; : { } , \ & q u o t ; a r e a \ & q u o t ; : { } , \ & q u o t ; g r a p h i c s \ & q u o t ; : { } , \ & q u o t ; s h o w I n D a t a W i n d o w \ & q u o t ; : t r u e , \ & q u o t ; v i s i b l e \ & q u o t ; : t r u e , \ & q u o t ; s h o w S t u d y A r g u m e n t s \ & q u o t ; : t r u e , \ & q u o t ; i n t e r v a l s V i s i b i l i t i e s \ & q u o t ; : { \ & q u o t ; t i c k s \ & q u o t ; : t r u e , \ & q u o t ; s e c o n d s \ & q u o t ; : t r u e , \ & q u o t ; s e c o n d s F r o m \ & q u o t ; : 1 , \ & q u o t ; s e c o n d s T o \ & q u o t ; : 5 9 , \ & q u o t ; m i n u t e s \ & q u o t ; : t r u e , \ & q u o t ; m i n u t e s F r o m \ & q u o t ; : 1 , \ & q u o t ; m i n u t e s T o \ & q u o t ; : 5 9 , \ & q u o t ; h o u r s \ & q u o t ; : t r u e , \ & q u o t ; h o u r s F r o m \ & q u o t ; : 1 , \ & q u o t ; h o u r s T o \ & q u o t ; : 2 4 , \ & q u o t ; d a y s \ & q u o t ; : t r u e , \ & q u o t ; d a y s F r o m \ & q u o t ; : 1 , \ & q u o t ; d a y s T o \ & q u o t ; : 3 6 6 , \ & q u o t ; w e e k s \ & q u o t ; : t r u e , \ & q u o t ; w e e k s F r o m \ & q u o t ; : 1 , \ & q u o t ; w e e k s T o \ & q u o t ; : 5 2 , \ & q u o t ; m o n t h s \ & q u o t ; : t r u e , \ & q u o t ; m o n t h s F r o m \ & q u o t ; : 1 , \ & q u o t ; m o n t h s T o \ & q u o t ; : 1 2 , \ & q u o t ; r a n g e s \ & q u o t ; : t r u e } , \ & q u o t ; p l o t s \ & q u o t ; : { \ & q u o t ; 0 \ & q u o t ; : { \ & q u o t ; i d \ & q u o t ; : \ & q u o t ; v o l \ & q u o t ; , \ & q u o t ; t y p e \ & q u o t ; : \ & q u o t ; l i n e \ & q u o t ; } , \ & q u o t ; 1 \ & q u o t ; : { \ & q u o t ; i d \ & q u o t ; : \ & q u o t ; v o l u m e P a l e t t e \ & q u o t ; , \ & q u o t ; p a l e t t e \ & q u o t ; : \ & q u o t ; v o l u m e P a l e t t e \ & q u o t ; , \ & q u o t ; t a r g e t \ & q u o t ; : \ & q u o t ; v o l \ & q u o t ; , \ & q u o t ; t y p e \ & q u o t ; : \ & q u o t ; c o l o r e r \ & q u o t ; } , \ & q u o t ; 2 \ & q u o t ; : { \ & q u o t ; i d \ & q u o t ; : \ & q u o t ; v o l _ m a \ & q u o t ; , \ & q u o t ; t y p e \ & q u o t ; : \ & q u o t ; l i n e \ & q u o t ; } } , \ & q u o t ; _ m e t a i n f o V e r s i o n \ & q u o t ; : 5 2 , \ & q u o t ; i s T V S c r i p t \ & q u o t ; : f a l s e , \ & q u o t ; i s T V S c r i p t S t u b \ & q u o t ; : f a l s e , \ & q u o t ; i s _ h i d d e n _ s t u d y \ & q u o t ; : f a l s e , \ & q u o t ; d e s c r i p t i o n \ & q u o t ; : \ & q u o t ; V o l u m e \ & q u o t ; , \ & q u o t ; s h o r t D e s c r i p t i o n \ & q u o t ; : \ & q u o t ; V o l u m e \ & q u o t ; , \ & q u o t ; i s _ p r i c e _ s t u d y \ & q u o t ; : f a l s e , \ & q u o t ; i d \ & q u o t ; : \ & q u o t ; V o l u m e @ t v - b a s i c s t u d i e s \ & q u o t ; , \ & q u o t ; f o r m a t \ & q u o t ; : { \ & q u o t ; t y p e \ & q u o t ; : \ & q u o t ; v o l u m e \ & q u o t ; } , \ & q u o t ; d e s c r i p t i o n _ l o c a l i z e d \ & q u o t ; : \ & q u o t ; V o l u m e \ & q u o t ; , \ & q u o t ; s h o r t I d \ & q u o t ; : \ & q u o t ; V o l u m e \ & q u o t ; , \ & q u o t ; p a c k a g e I d \ & q u o t ; : \ & q u o t ; t v - b a s i c s t u d i e s \ & q u o t ; , \ & q u o t ; v e r s i o n \ & q u o t ; : \ & q u o t ; 1 \ & q u o t ; , \ & q u ot;fullId\":\"Volume@tv-basicstudies-1\",\"productId\":\"tv-basicstudies\",\"name\":\"Volume@tv-basicstudies\",\"_serverMetaInfoVersion\":52},\"zorder\":-10000,\"ownFirstValue\":null,\"metaInfo\":{\"palettes\":{\"volumePalette\":{\"colors\":{\"0\":{\"name\":\"Falling\"},\"1\":{\"name\":\"Growing\"}}}},\"inputs\":[{\"id\":\"showMA\",\"name\":\"show MA\",\"defval\":false,\"type\":\"bool\",\"isHidden\":true},{\"id\":\"length\",\"name\":\"MA Length\",\"defval\":20,\"type\":\"integer\",\"min\":1,\"max\":2000},{\"defval\":false,\"id\":\"col_prev_close\",\"name\":\"Color based on previous close\",\"type\":\"bool\"}],\"plots\":[{\"id\":\"vol\",\"type\":\"line\"},{\"id\":\"volumePalette\",\"palette\":\"volumePalette\",\"target\":\"vol\",\"type\":\"colorer\"},{\"id\":\"vol_ma\",\"type\":\"line\"}],\"graphics\":{},\"defaults\":{\"styles\":{\"vol\":{\"linestyle\":0,\"linewidth\":1,\"plottype\":5,\"trackPrice\":false,\"transparency\":50,\"visible\":true,\"color\":\"#000080\"},\"vol_ma\":{\"linestyle\":0,\"linewidth\":1,\"plottype\":0,\"trackPrice\":false,\"transparency\":0,\"visible\":false,\"color\":\"#2196F3\"}},\"palettes\":{\"volumePalette\":{\"colors\":{\"0\":{\"color\":\"#EF5350\",\"width\":1,\"style\":0},\"1\":{\"color\":\"#26A69A\",\"width\":1,\"style\":0}}}},\"inputs\":{\"showMA\":false,\"length\":20,\"col_prev_close\":false}},\"_metainfoVersion\":52,\"isTVScript\":false,\"isTVScriptStub\":false,\"is_hidden_study\":false,\"styles\":{\"vol\":{\"title\":\"Volume\",\"histogramBase\":0},\"vol_ma\":{\"title\":\"Volume MA\",\"histogramBase\":0}},\"description\":\"Volume\",\"shortDescription\":\"Volume\",\"is_price_study\":false,\"id\":\"Volume@tv-basicstudies-1\",\"format\":{\"type\":\"volume\"},\"description_localized\":\"Volume\",\"shortId\":\"Volume\",\"packageId\":\"tv-basicstudies\",\"version\":\"1\",\"fullId\":\"Volume@tv-basicstudies-1\",\"productId\":\"tv-basicstudies\",\"name\":\"Volume@tv-basicstudies\",\"_serverMetaInfoVersion\":52}}],\"leftAxisesState\":[],\"rightAxisesState\":[{\"state\":{\"id\":\"AEh8VAL7anFf\",\"m_priceRange\":{\"m_maxValue\":505.6,\"m_minValue\":494},\"m_isAutoScale\":true,\"m_isPercentage\":false,\"m_isIndexedTo100\":false,\"m_isLog\":false,\"m_isLockScale\":false,\"m_isInverted\":false,\"m_height\":641.6,\"m_topMargin\":0.1,\"m_bottomMargin\":0.08,\"alignLabels\":true},\"sources\":[\"RGTnHz\"]}],\"overlayPriceScales\":{\"bl7jkV\":{\"id\":\"aYA6FWoeiTkP\",\"m_priceRange\":{\"m_maxValue\":298353,\"m_minValue\":0},\"m_isAutoScale\":true,\"m_isPercentage\":false,\"m_isIndexedTo100\":false,\"m_isLog\":false,\"m_isLockScale\":false,\"m_isInverted\":false,\"m_height\":641.6,\"m_topMargin\":0.1,\"m_bottomMargin\":0.08,\"alignLabels\":true}},\"stretchFactor\":2000,\"mainSourceId\":\"RGTnHz\",\"priceScaleRatio\":null}],\"timeScale\":{\"m_barSpacing\":6,\"m_rightOffset\":10},\"chartProperties\":{\"paneProperties\":{\"backgroundType\":\"solid\",\"background\":\"#ffffff\",\"backgroundGradientStartColor\":\"#ffffff\",\"backgroundGradientEndColor\":\"#ffffff\",\"vertGridProperties\":{\"color\":\"rgba(42,  46, 57, 0.06)\",\"style\":0},\"horzGridProperties\":{\"color\":\"rgba(42, 46, 57, 0.06)\",\"style\":0},\"crossHairProperties\":{\"color\":\"#9598A1\",\"style\":2,\"transparency\":0,\"width\":1},\"topMargin\":10,\"bottomMargin\":8,\"axisProperties\":{\"autoScale\":true,\"autoScaleDisabled\":false,\"lockScale\":false,\"percentage\":false,\"percentageDisabled\":false,\"indexedTo100\":false,\"log\":false,\"logDisabled\":false,\"alignLabels\":true,\"isInverted\":false},\"legendProperties\":{\"showStudyArguments\":true,\"showStudyTitles\":true,\"showStudyValues\":true,\"showSeriesTitle\":true,\"showSeriesOHLC\":true,\"showLegend\":true,\"showBarChange\":true,\"showBackground\":true,\"backgroundTransparency\":50,\"wrapText\":false}},\"scalesProperties\":{\"backgroundColor\":\"#ffffff\",\"lineColor\":\"rgba(42, 46, 57, 0.14)\",\"textColor\":\"#131722\",\"fontSize\":12,\"scaleSeriesOnly\":false,\"showSeriesLastValue\":true,\"seriesLastValueMode\":1,\"showSeriesPrevCloseValue\":false,\"showStudyLastValue\":false,\"showSymbolLabels\":false,\"showStudyPlotLabels\":false,\"showBidAskLabels\":false,\"showPrePostMarketPriceLabel\":true,\"showFundamentalNameLabel\":false,\"showFundamentalLastValue\":false,\"barSpacing\":6,\"showCurrency\":true,\"showUnit\":true},\"chartEventsSourceProperties\":{\"visible\":true,\"futureOnly\":true,\"breaks\":{\"color\":\"rgba(85, 85, 85, 1)\",\"visible\":false,\"style\":2,\"width\":1}},\"tradingProperties\":{\"showPositions\":true,\"positionPL\":{\"visibility\":true,\"display\":0},\"showOrders\":true,\"showExecutions\":true,\"horizontalAlignment\":0,\"extendLeft\":true,\"lineLength\":5,\"lineWidth\":1,\"lineStyle\":0},\"priceScaleSelectionStrategyName\":\"auto\"},\"lineToolsGroups\":{\"groups\":[]},\"version\":3,\"timezone\":\"Asia/Kolkata\",\"sessions\":{\"properties\":{\"graphics\":{\"backgrounds\":{\"outOfSession\":{\"color\":\"#2962FF\",\"transparency\":92,\"visible\":false},\"preMarket\":{\"color\":\"#FF9800\",\"transparency\":92,\"visible\":false},\"postMarket\":{\"color\":\"#2962FF\",\"transparency\":92,\"visible\":false}},\"vertlines\":{\"sessBreaks\":{\"color\":\"#4985e7\",\"style\":2,\"visible\":false,\"width\":1}}}}},\"shouldBeSavedEvenIfHidden\":false,\"chartId\":\"1\"}]}"}},
"symbol": "string",
"resolution": "string"
}
Я попробовал следующее объявление BaseModel и асинхронную функцию:

Код: Выделить всё

class Item(BaseModel):
name: str
content: dict
symbol: str
resolution: str

@app.post("/saveload/v1/charts")
async def create_item(item: Item, q: str | None = None):
return item
но это приводит к ошибке 422 Unprocessable Entity, потому что, как вы можете видеть, dict заключает JSON в фигурные скобки, из-за чего FastAPI выдает это ошибка. Итак, как мне объявить BaseModel, чтобы получить эти данные? Заранее спасибо.


Подробнее здесь: https://stackoverflow.com/questions/720 ... -object-in
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»