質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

SOAP

SOAP(Simple Object Access Protocol)はウェブサービス実装においての構造化された情報をやり取りするためのプロトコル規定です。

XSD

XSDは一般的に、XMLドキュメントの特定のタイプの表現を含んだ、W3C XML Schemaフォーマットで書かれたドキュメントを指します。

Authentication

Authentication(認証)は正当性を認証する為の工程です。ログイン処理等で使われます。

Q&A

解決済

1回答

1752閲覧

pythonでsoapheaderに認証情報を入れる方法について

sarasa_38765

総合スコア34

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

SOAP

SOAP(Simple Object Access Protocol)はウェブサービス実装においての構造化された情報をやり取りするためのプロトコル規定です。

XSD

XSDは一般的に、XMLドキュメントの特定のタイプの表現を含んだ、W3C XML Schemaフォーマットで書かれたドキュメントを指します。

Authentication

Authentication(認証)は正当性を認証する為の工程です。ログイン処理等で使われます。

0グッド

0クリップ

投稿2020/05/22 09:22

###以下のサービスをpythonから利用すべく、先方からユーザーID、パスワードを頂いたのですが認証がうまくいきません。WSDLを見てみるとsoapheaderに入れているようなのですが入れる方法が分かりません。

http://wstest.railgo.jp/Expservice10.asmx?WSDL

WSDL

1Prefixes: 2 xsd: http://www.w3.org/2001/XMLSchema 3 ns0: http://expart.est.co.jp/ExpService 4 5Global elements: 6 ns0:Authentication(ns0:Authentication) 7 ns0:GetDefaultNavigation() 8 ns0:GetDefaultNavigationResponse(GetDefaultNavigationResult: ns0:Navigation) 9 ns0:GetUserPoints(Date: xsd:dateTime) 10 ns0:GetUserPointsResponse(GetUserPointsResult: xsd:int) 11 ns0:SearchCourse(Stations: ns0:ArrayOfStation, SearchOption: ns0:Navigation) 12 ns0:SearchCourseAll(DepartureStations: ns0:ArrayOfStation, ArrivalStations: ns0:ArrayOfStation, SearchOption: ns0:Navigation) 13 ns0:SearchCourseAllResponse(SearchCourseAllResult: ns0:ArrayOfCourse) 14 ns0:SearchCourseResponse(SearchCourseResult: ns0:ArrayOfCourse) 15 ns0:SearchStation(StationYomi: xsd:string, AreaType: ns0:AreaType, StationType: ns0:StationType, Date: xsd:int) 16 ns0:SearchStationAll(StationYomiArray: ns0:ArrayOfString, AreaType: ns0:AreaType, StationType: ns0:StationType, Date: xsd:int) 17 ns0:SearchStationAllResponse(SearchStationAllResult: ns0:ArrayOfArrayOfStation) 18 ns0:SearchStationResponse(SearchStationResult: ns0:ArrayOfStation) 19 20 21Global types: 22 xsd:anyType 23 ns0:AirlineFareType 24 ns0:AreaType 25 ns0:ArrayOfArrayOfStation(ArrayOfStation: ns0:ArrayOfStation[]) 26 ns0:ArrayOfCourse(Course: ns0:Course[]) 27 ns0:ArrayOfFare(Fare: ns0:Fare[]) 28 ns0:ArrayOfFareSection(FareSection: ns0:FareSection[]) 29 ns0:ArrayOfPassSection(PassSection: ns0:PassSection[]) 30 ns0:ArrayOfRouteSection(RouteSection: ns0:RouteSection[]) 31 ns0:ArrayOfStation(Station: ns0:Station[]) 32 ns0:ArrayOfStationType(StationType: ns0:StationType[]) 33 ns0:ArrayOfString(string: xsd:string[]) 34 ns0:ArrayOfSurchargeSection(SurchargeSection: ns0:SurchargeSection[]) 35 ns0:Authentication(User: xsd:string, Password: xsd:string, _attr_1: {}) 36 ns0:CareState 37 ns0:Corporation(Name: xsd:string, LineType: ns0:LineType) 38 ns0:Course(Description: xsd:string, Stations: ns0:ArrayOfStation, RouteSections: ns0:ArrayOfRouteSection, FareSections: ns0:ArrayOfFareSection, SurchargeSections: ns0:ArrayOfSurchargeSection, PassSections: ns0:ArrayOfPassSection, TotalTime: xsd:int, TotalBoardTime: xsd:int, TotalWalkTime: xsd:int, TotalOtherTime: xsd:int, TransferCount: xsd:int, TotalDistance: xsd:int, PassFare: ns0:PassSection, TotalFare: ns0:Fare, TotalSurcharge: ns0:Fare) 39 ns0:Fare(OneWayFare: xsd:decimal, RoundTripFare: xsd:decimal, airlineFareType: ns0:AirlineFareType, SurchaegeSeatType: ns0:SeatType, FareTypeName: xsd:string) 40 ns0:FareSection(StationFrom: ns0:Station, StationTo: ns0:Station, FareList: ns0:ArrayOfFare, Comment: xsd:string) 41 ns0:GeodeticDatum(bearing: xsd:string, degree: xsd:int, minutes: xsd:int, second: xsd:decimal) 42 ns0:Line(lineType: ns0:LineType, Name: xsd:string, LongName: xsd:string, ShortName: xsd:string, OperationCorporation: ns0:Corporation, Color: xsd:int, StopStations: ns0:ArrayOfStation) 43 ns0:LineType 44 ns0:Navigation(AnswerCount: xsd:int, TargetDate: xsd:int, TargetTime: xsd:int, Departure: xsd:boolean, SurchargeKind: ns0:SeatType, PassType: ns0:PassType, IgnoreSeasonJR: xsd:boolean, IncludeInsuranceSurcharge: xsd:boolean, TicketSystem: ns0:TicketSystem, FuzzyLine: xsd:boolean, Airplane: ns0:UseState, Express: ns0:UseState, JR: ns0:UseState, Walk: ns0:CareState, Change: ns0:CareState, UseLocalBus: xsd:boolean, HighwayBus: ns0:UseState, ConnectionBus: ns0:UseState, WaitTime: ns0:WaitTimeState, StartStation: ns0:UseState, SleepingTrain: ns0:UseState, LocalBusOnly: xsd:boolean, Sort: ns0:SortType) 45 ns0:PassSection(StationFrom: ns0:Station, StationTo: ns0:Station, OneMonth: xsd:int, ThreeMonth: xsd:int, SixMonth: xsd:int, FreePass: xsd:boolean) 46 ns0:PassType 47 ns0:RouteSection(Line: ns0:Line, Train: ns0:Train, StationFrom: ns0:Station, StationTo: ns0:Station, LineType: ns0:LineType, Distance: xsd:int, CorpName: xsd:string, ConnectedSection: xsd:boolean, BackSection: xsd:boolean, StopStations: ns0:ArrayOfStation) 48 ns0:SeatType 49 ns0:SortType 50 ns0:Station(Types: ns0:ArrayOfStationType, Name: xsd:string, LongName: xsd:string, LineName: xsd:string, ShortName: xsd:string, Yomi: xsd:string, LandmarkCategory: xsd:string, LandmarkNearestStation: ns0:ArrayOfStation, LandmarkNearestStationTransfer: ns0:ArrayOfCourse, Latitude: ns0:GeodeticDatum, Longitude: ns0:GeodeticDatum) 51 ns0:StationType 52 ns0:SurchargeSection(SurchargeFrom: ns0:Station, SurchargeTo: ns0:Station, Surcharges: ns0:ArrayOfFare) 53 ns0:TicketSystem 54 ns0:Train(ID: xsd:int, TimetableDate: xsd:int, DepartureTime: xsd:int, ArrivalTime: xsd:int) 55 ns0:UseState 56 ns0:WaitTimeState 57 xsd:ENTITIES 58 xsd:ENTITY 59 xsd:ID 60 xsd:IDREF 61 xsd:IDREFS 62 xsd:NCName 63 xsd:NMTOKEN 64 xsd:NMTOKENS 65 xsd:NOTATION 66 xsd:Name 67 xsd:QName 68 xsd:anySimpleType 69 xsd:anyURI 70 xsd:base64Binary 71 xsd:boolean 72 xsd:byte 73 xsd:date 74 xsd:dateTime 75 xsd:decimal 76 xsd:double 77 xsd:duration 78 xsd:float 79 xsd:gDay 80 xsd:gMonth 81 xsd:gMonthDay 82 xsd:gYear 83 xsd:gYearMonth 84 xsd:hexBinary 85 xsd:int 86 xsd:integer 87 xsd:language 88 xsd:long 89 xsd:negativeInteger 90 xsd:nonNegativeInteger 91 xsd:nonPositiveInteger 92 xsd:normalizedString 93 xsd:positiveInteger 94 xsd:short 95 xsd:string 96 xsd:time 97 xsd:token 98 xsd:unsignedByte 99 xsd:unsignedInt 100 xsd:unsignedLong 101 xsd:unsignedShort 102 103Bindings: 104 Soap11Binding: {http://expart.est.co.jp/ExpService}ExpService10Soap 105 Soap12Binding: {http://expart.est.co.jp/ExpService}ExpService10Soap12 106 107Service: ExpService10 108 Port: ExpService10Soap (Soap11Binding: {http://expart.est.co.jp/ExpService}ExpService10Soap) 109 Operations: 110 GetDefaultNavigation(_soapheaders={Authentication: ns0:Authentication}) -> GetDefaultNavigationResult: ns0:Navigation 111 GetUserPoints(Date: xsd:dateTime, _soapheaders={Authentication: ns0:Authentication}) -> GetUserPointsResult: xsd:int 112 SearchCourse(Stations: ns0:ArrayOfStation, SearchOption: ns0:Navigation, _soapheaders={Authentication: ns0:Authentication}) -> SearchCourseResult: ns0:ArrayOfCourse 113 SearchCourseAll(DepartureStations: ns0:ArrayOfStation, ArrivalStations: ns0:ArrayOfStation, SearchOption: ns0:Navigation, _soapheaders={Authentication: ns0:Authentication}) -> SearchCourseAllResult: ns0:ArrayOfCourse 114 SearchStation(StationYomi: xsd:string, AreaType: ns0:AreaType, StationType: ns0:StationType, Date: xsd:int, _soapheaders={Authentication: ns0:Authentication}) -> SearchStationResult: ns0:ArrayOfStation 115 SearchStationAll(StationYomiArray: ns0:ArrayOfString, AreaType: ns0:AreaType, StationType: ns0:StationType, Date: xsd:int, _soapheaders={Authentication: ns0:Authentication}) -> SearchStationAllResult: ns0:ArrayOfArrayOfStation 116 117 Port: ExpService10Soap12 (Soap12Binding: {http://expart.est.co.jp/ExpService}ExpService10Soap12) 118 Operations: 119 GetDefaultNavigation(_soapheaders={Authentication: ns0:Authentication}) -> GetDefaultNavigationResult: ns0:Navigation 120 GetUserPoints(Date: xsd:dateTime, _soapheaders={Authentication: ns0:Authentication}) -> GetUserPointsResult: xsd:int 121 SearchCourse(Stations: ns0:ArrayOfStation, SearchOption: ns0:Navigation, _soapheaders={Authentication: ns0:Authentication}) -> SearchCourseResult: ns0:ArrayOfCourse 122 SearchCourseAll(DepartureStations: ns0:ArrayOfStation, ArrivalStations: ns0:ArrayOfStation, SearchOption: ns0:Navigation, _soapheaders={Authentication: ns0:Authentication}) -> SearchCourseAllResult: ns0:ArrayOfCourse 123 SearchStation(StationYomi: xsd:string, AreaType: ns0:AreaType, StationType: ns0:StationType, Date: xsd:int, _soapheaders={Authentication: ns0:Authentication}) -> SearchStationResult: ns0:ArrayOfStation 124 SearchStationAll(StationYomiArray: ns0:ArrayOfString, AreaType: ns0:AreaType, StationType: ns0:StationType, Date: xsd:int, _soapheaders={Authentication: ns0:Authentication}) -> SearchStationAllResult: ns0:ArrayOfArrayOfStation 125 126 127

###zeepのところでサンプルは見つけてきたのですが、ns0:Authentication(User: xsd:string, Password: xsd:string, _attr_1: {})の分をどうhedderの記述すれば良いのかわかりません。

python

1from zeep import xsd 2 3header = xsd.Element( 4 '{http://test.python-zeep.org}auth', 5 xsd.ComplexType([ 6 xsd.Element( 7 '{http://test.python-zeep.org}username', 8 xsd.String()), 9 ]) 10) 11header_value = header(username='mvantellingen') 12client.service.Method(_soapheaders=[header_value]) 13

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

client = Client('http://wstest.railgo.jp/Expservice10.asmx?WSDL')
order_type = client.get_element('ns0:Authentication')
order = order_type(User='***********', Password='**********',_attr_1={})
client.service.GetDefaultNavigation(_soapheaders={"Authentication":order})

分かってみればたった4行でした。

投稿2020/05/25 10:29

sarasa_38765

総合スコア34

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問